1

我试图弄清楚如何将点和线(彩色)添加到 R 中的图例中。

我想要绘制的是这样的:

x = 1:10
y = sin(x)
z = cos(x)

plot(x,y,type='l',lty=2,col="blue")
points(x,z,pch=19,col="red")

#I know this legend command doesn't work, but I just want to explain what I want
legend("topleft",c("x","y"),pch=19,lty=2,col=c("red","blue")

如您所见,我希望能够在图例中同时包含点和线(具有正确的类型和颜色)。

4

1 回答 1

4

您将 NA 值作为pch=and的其他参数lty=

legend("topleft",c("x","y"),pch=c(19,NA),lty=c(NA,2),col=c("red","blue"))
于 2013-07-24T19:26:23.333 回答