在R图例中添加pch符号

时间:2022-01-30 15:02:10

I have one time series which is represented by a black line and one which is represented by a red curve. Then I have single points which have the pch symbol of 8 in R. These are stars. See the following plot: 在R图例中添加pch符号

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

Currently I have the following legend:

目前我有以下传说:

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))

But I don't want to have a blue line in the legend for exceedance, but just the stars in the plot. I have to use the pch=8. I just want to have the stars in the legend, not the stars with a line. So not these solutions: R legend issue, symbols of points are masked by lines

但我不想在传说中有一条蓝线超过,而只是在情节中的星星。我必须使用pch = 8。我只想拥有传奇中的星星,而不是带有线条的星星。所以不是这些解决方案:R传奇问题,点的符号被线条掩盖

1 个解决方案

#1


26  

Try this. You set lty to display only first two lines, and pch to display only the last point.

尝试这个。您将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))

在R图例中添加pch符号

#1


26  

Try this. You set lty to display only first two lines, and pch to display only the last point.

尝试这个。您将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))

在R图例中添加pch符号