如何在R

我运行以下代码:

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

但是我得到的结果如下:

wrong legend

如何修复图例?

nt890121 回答:如何在R

您需要一个图例,因为每次运行后都会生成新图,请使用

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

这是输出

enter image description here

本文链接:https://www.f2er.com/3067497.html

大家都在问