如何在ecdf情节中添加图例?

use*_*956 0 r

我正在生成一个ecdf情节,并希望添加一个图例,但收到以下错误:

plot(xlim=c(0,100), ylim=c(0,1), main=NULL, xaxs="i", yaxs="i", 
     ecdf(PrecentageVector1),  col="red", do.p = FALSE, pch=19, 
     lwd=3,  legend("bottomleft",c("A","B","C")), panel.first = grid()) 

Error in strwidth(legend, units = "user", cex = cex, font = text.font) :  
invalid graphics state
Run Code Online (Sandbox Code Playgroud)

可能是什么问题呢?

the*_*ail 5

?legend它本身就是一个函数,它不是plot调用的一部分.正如@timriffe所说,你需要做的事情如下:

PrecentageVector1 <- c(10,20,30)
plot(xlim=c(0,100), ylim=c(0,1), main=NULL, xaxs="i", yaxs="i", 
     ecdf(PrecentageVector1),  col="red", do.p = FALSE, pch=19, 
     lwd=3, panel.first = grid()) 
legend("bottomleft",c("A","B","C"))
Run Code Online (Sandbox Code Playgroud)

  • 现在你提到它,`panel.last = legend(`...`)`适用于提问者.就像`panel.first = {grid(); 传说(`...`)}`.不是很有趣.我想我会坚持使用格子. (3认同)