Time series plot range

雨燕双飞 提交于 2019-12-10 19:06:14

问题


Hi am ploting a xts object:

And I would like to extend the xlim til 30-february because I want to add the prediction from an Arima model:

par(mfrow=c(1,1))
pred <- predict(try2, n.ahead = 1,se.fit=T)
lim_sup <- pred$pred + 1.96 * pred$se
lim_inf <- pred$pred - 1.96 * pred$se
plot(heat["1996-02-01 00:00/1996-02-16 04:00"],type="l",main="Cross Validation")
points(exp(pred$pred),col="blue",lwd=2)
points(exp(lim_sup),lwd=2,col="green")
points(exp(lim_inf),lwd=2,col="green")

But I can not see any lines in the plot. Could you give me some recommendation?

The heat time series looks like this

                     HC.f
1996-02-01 00:00:00 1437.000
1996-02-01 01:00:00 1441.600
1996-02-01 02:00:00 1489.300
1996-02-01 03:00:00 1501.300
1996-02-01 04:00:00 1568.400
1996-02-01 05:00:00 1629.400

While the predictions for one hour step:

pred$pred
Time Series:
Start = 3002 
End  = 3002 
Frequency = 1 
[1] 7.480588

回答1:


Merge your actual and prediction objects before plotting. Then you will have one time series over the full desired time period.

library(xts)
set.seed(21)
x <- xts(rnorm(10),Sys.Date()-10:1)
y <- xts(rnorm(3),Sys.Date()+0:2)
z <- merge(x,y)
plot(z[,1], ylim=range(z,na.rm=TRUE))
lines(z[,2],col='red')


来源:https://stackoverflow.com/questions/16164989/time-series-plot-range

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!