首页 > 解决方案 > “plot.xy(xy.coords(x, y), type = type, ...) 中的错误:尚未调用 plot.new”

问题描述

当我想要线时,R中的线函数会出现一些不寻常的错误

lines(soy$Year,ci_soy[,1],col='black',lwd=3)

lines(soy$Year,ci_soy[,1],type="l", col="green", lwd=3,xlab="Year", ylab="bu_acre")

plot(soy$Year,ci_soy[,1],type="l", col="green", lwd=3,xlab="Year", ylab="bu_acre")

在此处输入图像描述

标签: r

解决方案


简单的解决方案应该是:首先调用这行代码

plot(mtcars$disp,ci_mtcars[,1],type="l", col="green", lwd=3,xlab="disp", ylab="bu_acre")

说明:在基础 R 中,首先您必须开始一个绘图plot以生成绘图。在此图中,lines可以添加您的功能。看我的例子:

# without plot

lines(iris$Sepal.Length, col='black',lwd=3)

Output:
error in plot.xy(xy.coords(x, y), type = type, ...) : 
  plot.new has not been called yet

# with plot

# empty plot frame for lines
plot(1, type="n", xlab="", ylab="", xlim=c(0, 100), ylim=c(0, 10))
lines(iris$Sepal.Length, col='black',lwd=3)

输出: 在此处输入图像描述


推荐阅读