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

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

Adding a character within "bquote" in legend

问题

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

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

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

  1. x <- 1:100
  2. y <- x^2
  3. plot(x, y)
  4. i <- 5
  5. legend("topleft",
  6. legend=c(c(as.expression(bquote("X"[.(i)]))),
  7. 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

  1. legend("topleft", legend=c(c(as.expression(bquote("today" "X"[.(i)]))),
  2. as.expression(bquote("tommorrow" "X"[.(i)]))),
  3. 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.

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

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

英文:

You can use bquote independently of expression.

  1. plot.new();plot.window(c(1, 100), c(1, 1e3));box()
  2. i &lt;- 5; j &lt;- 6
  3. legend(&#39;topleft&#39;, legend=c(bquote(today~X[.(i)]),
  4. bquote(tomorrow~X[.(j)])),
  5. 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:

确定