簡體   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