【问题标题】:autoplot using wrong time for xts为 xts 使用错误的时间自动绘图
【发布时间】:2020-02-28 08:08:33
【问题描述】:
我使用autoplot() 函数绘制了一个时间序列数据,包括来自forecast() 函数的有马预测。图的 x 轴是错误的。数据使用xts从2000/01/01到2019/09/01,但是显然结果没有使用这个时间。
fed.arima <- auto.arima(FEDFUNDS_ts)
fore1 <- forecast(fed.arima,level = c(95),h=12)
plot(fore1)
autoplot(fore1)
plot(fore1)
enter image description here
【问题讨论】:
标签:
r
ggplot2
xts
arima
forecast
【解决方案1】:
也许您的时间数据是字符类型。所以更改时间或日期类型的数据。
例子:
str(data)
'data.frame': ~ obs. of ~ variables:
$ Time: chr "2017/7/1" "2017/7/2" "2017/7/3" "2017/7/4 " ...
library(lubridate)
data$Time<-ymd(data$Time)
str(data)
'data.frame': ~ obs. of ~ variables:
$ Time: Date, format "2017-7-1" "2017-7-2" "2017-7-3" "2017-7-4 " ...
并尝试制作情节。