在图例中在“bquote”内添加一个字符

huangapple go评论76阅读模式
英文:

Adding a character within "bquote" in legend

问题

legend中的bquote中添加一个词如“today X5”的方法是:

legend("topleft",
       legend=c(paste("today ", as.expression(bquote("X"[.(i)])))),
       col=c(1, 2), pch=c(2, 3))
英文:

How can I add a word within the bquote in the legend? Using the code

x <- 1:100
y <- x^2
plot(x, y)
i <- 5
legend("topleft",
       legend=c(c(as.expression(bquote("X"[.(i)]))), 
                as.expression(bquote("X"[.(i)]))), col=c(1, 2), pch=c(2, 3))

I got
this
but i want a legend box where a word before the math expression X5 will be placed such as today X5.

So I use

legend("topleft", legend=c(c(as.expression(bquote("today" "X"[.(i)]))),
                          as.expression(bquote("tommorrow" "X"[.(i)]))),
       col=c(1, 2), pch=c(2, 3))

but this gave me error. How could I get my desired legend box?

答案1

得分: 3

You can use bquote independently of expression.

plot.new(); plot.window(c(1, 100), c(1, 1e3)); box()

i <- 5; j <- 6
legend('topleft', legend=c(bquote(today~X[.(i)]),
                           bquote(tomorrow~X[.(j)])), 
       col=1:2, pch=2:3)

在图例中在“bquote”内添加一个字符

英文:

You can use bquote independently of expression.

plot.new();plot.window(c(1, 100), c(1, 1e3));box()

i &lt;- 5; j &lt;- 6
legend(&#39;topleft&#39;, legend=c(bquote(today~X[.(i)]),
                           bquote(tomorrow~X[.(j)])), 
       col=1:2, pch=2:3)

在图例中在“bquote”内添加一个字符

huangapple
  • 本文由 发表于 2023年6月26日 08:08:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76552873.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定