我已尝试针对其他类似问题(plot.new(), combining chunks和newplot)建议的答案,但错误仍然相同。
library(ggplot2)
library(lattice)
library(segmented)
library(mixtools)
plot(kreg.best$fitted.x,kreg.best$fitted.y,
newplot=TRUE, draw=TRUE,
type="l",col="blue",
xlab="Days of the Year",ylab="Birth Rate",
main="Kernel Regression Model and Bootstrap Confidence Intervals",
shadebands(kreg.best$fitted.x,percentile.ci.bounds[1,],percentile.ci.bounds[2,],col=transparentgray))
Error in polygon(c(x, rev(x)), y = c(lo, rev(hi)), col = col, border = NA) : plot.new has not been called yet
唯一的区别是我在代码的其余部分之前调用了plot(0, ...),并且生成了一个折线图,但没有阴影带。这是它的样子: RStudio output with plot(0,...) command