我试图弄清楚如何将点和线(彩色)添加到 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")
如您所见,我希望能够在图例中同时包含点和线(具有正确的类型和颜色)。