简体   繁体   English

在R图例中添加pch符号

[英]Add pch symbol in R plot legend

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. 然后我有单点在R中有pch符号8。这些是星星。 See the following plot: 见下图: 明星

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. 我必须使用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 所以不是这些解决方案: R传奇问题,点的符号被线条掩盖

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

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM