我想在我的情节中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)
所以左边的图例是手动创建的,我想要的输出是在右边创建相同的。
答案 0 :(得分:1)
你很亲密。我相信这就是你想要的:
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)