我运行以下代码:
plot(1:3,rnorm(3),pch = 1,lty = 1,type = "o",ylim=c(-2,2))
lines(1:3,pch = 2,lty = 2,type="o")
legend(1,-1,c("group A","group B"),pch = c(1,2),lty = c(1,2))
但是我得到的结果如下:
如何修复图例?
您需要一个图例,因为每次运行后都会生成新图,请使用
plot(1:3,rnorm(3),pch = 1,lty = 1,type = "o",ylim=c(-2,2))
lines(1:3,pch = 2,lty = 2,type="o")
legend("bottomright",c("group A","group B"),pch = c(1,2),lty = c(1,inset=c(0,1),xpd=TRUE,horiz=TRUE,bty="n")
这是输出