繁体   English   中英

R中图例中的特殊符号

[英]Special symbols in legend in R

我想在情节的图例中写特殊符号,例如 5<# of events<=20。 到目前为止,我已经尝试了多个代码,但没有奏效。

我不知道为什么这不起作用bquote(5<~"# of events"~<=20)

我终于完成了这项工作(以一种笨拙的方式): legend_txt <- c(bquote('5 < # of counties' <= 20), bquote('20 < # of counties' <= 60), bquote('60 < # of counties' <= 100), bquote('# of counties' >= 100))但正如你所见,< 与图例中的 <= 不同。 有人可以帮我弄这个吗? 谢谢!

示例代码:

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)

在此处输入图像描述

我不确定这是否是您正在寻找的。 在 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)

reprex 包(v2.0.1)于 2022-06-04 创建

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM