我正在生成一个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)
可能是什么问题呢?
?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)