[英]Special symbols in legend in R
I want to write special symbols in the legend in a plot, like 5<# of events<=20.我想在情节的图例中写特殊符号,例如 5<# of events<=20。 So far I've tried multiple codes but didn't work.
到目前为止,我已经尝试了多个代码,但没有奏效。
I don't know why this doesn't work bquote(5<~"# of events"~<=20)
我不知道为什么这不起作用
bquote(5<~"# of events"~<=20)
I finally made this work (in a clumsy way): legend_txt <- c(bquote('5 < # of counties' <= 20), bquote('20 < # of counties' <= 60), bquote('60 < # of counties' <= 100), bquote('# of counties' >= 100))
But as you can see, the < is different from <= in the legend.我终于完成了这项工作(以一种笨拙的方式):
legend_txt <- c(bquote('5 < # of counties' <= 20), bquote('20 < # of counties' <= 60), bquote('60 < # of counties' <= 100), bquote('# of counties' >= 100))
但正如你所见,< 与图例中的 <= 不同。 Can someone help me with this?有人可以帮我弄这个吗? Thanks!
谢谢!
example code:示例代码:
x = c(0, 5, 10, 15)
y = c(2.2, 3.8, 4.6, 7.6)
z = c(4.5, 6.8, 9.3, 10.5)
plot(x, y, type="l", lwd=2, col=1, ylim=c(0, 12))
lines(x,z, lwd=2, col=2)
legend_txt <- c(bquote('5 < # events' <= 20),bquote('20 < # of events' <= 60))
legend('topright', legend = legend_txt, col = 1:2, lty = 1)
I am not sure that this is what you are looking for.我不确定这是否是您正在寻找的。 Put two tildes before the 5 and the legends align.
在 5 之前放置两个波浪号,图例对齐。
x = c(0, 5, 10, 15)
y = c(2.2, 3.8, 4.6, 7.6)
z = c(4.5, 6.8, 9.3, 10.5)
plot(x, y, type="l", lwd=2, col=1, ylim=c(0, 12))
lines(x,z, lwd=2, col=2)
legend_txt <- c(bquote(~~5 <~ '# of events' <= 20),
bquote(20 <~ '# of events' <= 60))
legend('topright', legend = legend_txt, col = 1:2, lty = 1)
Created on 2022-06-04 by the reprex package (v2.0.1)由reprex 包(v2.0.1)于 2022-06-04 创建
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.