主な問題は、fc1_ETSがリストではなくベクトルであるということでした。以下のコードのガイドラインに従ってください。お役に立てれば!
library(rdatamarket)
library(Quandl)
library(forecast)
library(dplyr)
library(graphics)
# Reading the data
ausgdp <- as.ts(dmseries("http://data.is/1jDQwpr")[,1])
# You should always calculate the forecasts before ploting. This will save you the adjustments in x axis scales
orig.points <- ausgdp
ets.points <- forecast(ausgdp,h=5)
arima.points <- auto.arima(ausgdp) %>% forecast(h=5)
# Note that ets.poins and arima.points are lists
ets.points <- ets.points$mean
# for arima, you have to combine the forecasts with the original data
arima.points <- c(orig.points, arima.points$mean)
# Now we are ready to plot
dt <- cbind(ets.points, arima.points, orig.points)
matplot(y=dt, x = seq(1960, length.out = length(arima.points)),
col=c("salmon1", "cornflowerblue", "darkblue"), lwd=2, pch=20, type="o", xlab="time",
ylab="Forecasts", lty = 1, cex = 1.25)
grid()
# adding a legend
legend <- paste("-", c("ETS", "ARIMA", "original"))
col=c("salmon1", "cornflowerblue", "darkblue")
olegend <- legend
for (i in 1:length(olegend)) {
xlegend <- legend
xlegend <- paste0("'", legend, "'")
xlegend[-i] <- paste0("phantom(`", xlegend[-i], "`)")
xlegend <- paste0(xlegend, collapse = " * ")
xlegend <- paste0("expression(", xlegend, ")")
xlegend <- paste0("mtext(", xlegend, ",col = '", col[i],
"',line = ", 0, ",side = ", 3, ",adj = ", 1,
",cex = ", 0.8, ")")
eval(parse(text = xlegend))
}
はStackOverflowのへようこそ! [良い質問をする方法](http://stackoverflow.com/help/how-to-ask)と[再現可能な例を与える方法](http://stackoverflow.com/questions/)の情報をお読みください。 5963269)。これは他の人があなたを助けることをはるかに容易にします。 – Jaap
質問を投稿する前にこの[How to Ask](http://stackoverflow.com/help/how-to-ask)を見て、ツアーを受けてください – Prasad