英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论