[英]combining legend and paste command in base R plot
我想將一些文本paste()
到圖例中的圖例中,但是我無法讓R正確讀取c()
和paste()
命令。
plot(1:10,1:10,type="n")
a <- 23
b <- 32
legend("topleft",inset=0.05,
legend=c("1-15: n=[23]\nEstimated","15+: n=[32]\nAveraged"),
lty=c(1,1),col=c("black","red"),bty="n",cex=1.5)
legend("topright",inset=0.05,
legend=c(paste("1-15: n=[",a,"]\nEstimated","15+: n=[32]\nAveraged")),
lty=c(1,1),col=c("black","red"),bty="n",cex=1.5)
因此,左側的圖例是手動創建的,我想要的輸出是在右側創建相同的圖例。
你近了 我相信這就是您想要的:
plot(1:10, 1:10, type="n")
a <- 23
b <- 32
legend("topright", inset = 0.05,
legend = c(paste("1-15: n=[", a, "]\nEstimated"),
paste(" 15+: n=[", b, "]\nAveraged")),
lty = c(1,1),
col = c("black","red"), bty = "n", cex = 1.5)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.