在R图例中添加pch符号

时间:2013-04-14 08:25:56

标签: r formatting plot legend

我有一个时间序列,用黑线表示,一个用红色曲线表示。然后我有单点在R中有pch符号8。这些是星星。见下图: stars

目前我有以下传说:

legend("bottomleft", 
 legend=c("log loss","daily VaR","exceedance"),
 bty = "n",lwd=2, cex=1.2,y.intersp=1.4, col=c("black","red","blue"), lty=c(1,1,1))

但我不想在传说中有一条蓝线超出,而只是在情节中的星星。我必须使用pch = 8。我只想拥有传说中的星星,而不是带有线条的星星。所以不是这些解决方案:R legend issue, symbols of points are masked by lines

1 个答案:

答案 0 :(得分:29)

试试这个。您将lty设置为仅显示前两行,并将pch设置为仅显示最后一个点。

plot(1:10, rnorm(10) * 1:10)
legend("bottomleft", legend = c("entry1", "entry2", "something cpl different"), bty = "n",
       lwd = 2, cex = 1.2, col = c("black", "blue", "red"), lty = c(1, 1, NA), pch = c(NA, NA, 8))

enter image description here