R:如何填充这两条虚线之间的区域
我的名字是Ihsan,很抱歉我的英语不好理解 我需要帮助创建阴影或填充这两条虚线之间的区域作为我的预测“间隔” 我的数据是(作为ts对象): 我的代码是:R:如何填充这两条虚线之间的区域,r,ggplot2,plot,forecasting,confidence-interval,R,Ggplot2,Plot,Forecasting,Confidence Interval,我的名字是Ihsan,很抱歉我的英语不好理解 我需要帮助创建阴影或填充这两条虚线之间的区域作为我的预测“间隔” 我的数据是(作为ts对象): 我的代码是: library('tsintermittent') ts <- structure( c(0L, 208L, 112L, 39L, 65L, 38L, 17L, 54L, 105L, 0L, 66L, 24L, 0L, 0L, 69L, 421L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 10L),
library('tsintermittent')
ts <- structure(
c(0L, 208L, 112L, 39L, 65L, 38L, 17L, 54L, 105L, 0L, 66L, 24L,
0L, 0L, 69L, 421L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 10L),
.Tsp = c(2018, 2019 + 11/12, 12), class = 'ts'
)
crost.frc <- crost(ts,h=3,w=NULL,init="mean",nop=1,type="croston",
cost=c("mae","mse"),init.opt = F,
outplot = F,opt.on = F,na.rm = F)
tsobj <- ts(c(ts,rep(NA,3)),frequency=12,start=c(2018,1))
fit <- ts(crost.frc$frc.in,frequency=12,start=c(2018,1))
y <- ts(c(fit,crost.frc$frc.out),frequency=12,start=c(2018,1))
upconfint <- ts(c(rep(NA,23),fit[24],y[25:27]+1.96*sd(ts-na.omit(fit))),
frequency=12,start=c(2018,1))
lowconfint <- ts(c(rep(NA,23),fit[24],y[25:27]-1.96*sd(ts-na.omit(fit))),
frequency=12,start=c(2018,1))
#Plot Forecast - Croston
plot(tsobj,pch=16,type="o",main="Metode Croston",xlab="Periode",ylab="Demand")
points(y,pch=1,type="o",col="purple")
points(upconfint,type="l",lty=3,col="grey",lwd=2)
points(lowconfint,type="l",lty=3,col="grey",lwd=2)
points(fit,pch=1,type="o",col="red")
legend("topleft", legend=c("Aktual","Fit","Forecast","Interval"),
col=c("black","red","purple","grey"), lty=c(1,1,1,2), cex=0.8)
library('tInTermitent')
ts我从不处理时间序列,所以这可能是一条艰难的道路
如果你有这样的数据
x <- 1:5
y <- 1:5
polygon(c(x, rev(x)), c(y, rev(y)))
要获取x值,在stats::lines.ts
中使用的是time(ts)
其中ts
分别是upconfint
和lowconint
但是,如果希望在其他部分下绘制置信区间,则必须重新排序绘图:
plot(tsobj,pch=16,type="o",main="Metode Croston",xlab="Periode",ylab="Demand")
xx <- c(time(upconfint), rev(time(lowconfint)))
yy <- c(upconfint, rev(lowconfint))
polygon(xx, yy, col = 'grey95', border = NA)
points(upconfint,type="l",lty=3,col="grey",lwd=2)
points(lowconfint,type="l",lty=3,col="grey",lwd=2)
points(y,pch=1,type="o",col="purple")
points(fit,pch=1,type="o",col="red")
legend("topleft", legend=c("Aktual","Fit","Forecast","Interval"),
col=c("black","red","purple","grey"), lty=c(1,1,1,2), cex=0.8)
plot(tsobj,pch=16,type=“o”,main=“Metode Croston”,xlab=“Periode”,ylab=“Demand”)
xx我从不处理时间序列,所以这可能是一条艰难的道路
如果你有这样的数据
x <- 1:5
y <- 1:5
polygon(c(x, rev(x)), c(y, rev(y)))
要获取x值,在stats::lines.ts
中使用的是time(ts)
其中ts
分别是upconfint
和lowconint
但是,如果希望在其他部分下绘制置信区间,则必须重新排序绘图:
plot(tsobj,pch=16,type="o",main="Metode Croston",xlab="Periode",ylab="Demand")
xx <- c(time(upconfint), rev(time(lowconfint)))
yy <- c(upconfint, rev(lowconfint))
polygon(xx, yy, col = 'grey95', border = NA)
points(upconfint,type="l",lty=3,col="grey",lwd=2)
points(lowconfint,type="l",lty=3,col="grey",lwd=2)
points(y,pch=1,type="o",col="purple")
points(fit,pch=1,type="o",col="red")
legend("topleft", legend=c("Aktual","Fit","Forecast","Interval"),
col=c("black","red","purple","grey"), lty=c(1,1,1,2), cex=0.8)
plot(tsobj,pch=16,type=“o”,main=“Metode Croston”,xlab=“Periode”,ylab=“Demand”)
xx确保将dput(object)
的输出和您正在使用的任何库添加到您的问题中确保将dput(object)
的输出和您正在使用的任何库添加到您的问题中谢谢!这实际上回答了我的困惑,因为x轴是时间点,我不知道如何在多边形函数中返回它作为输入谢谢!这实际上解决了我的困惑,因为x轴是时间点,我不知道如何将其作为多边形函数的输入返回