我有每月数据,我想绘制预测值:
z <- structure(list(Date = structure(c(14610, 14641, 14669, 14700,
14730, 14761, 14791, 14822, 14853, 14883, 14914, 14944, 14975,
15006, 15034, 15065, 15095, 15126, 15156, 15187, 15218, 15248,
15279, 15309, 15340, 15371, 15400, 15431, 15461), class = "Date"),
Value = c(4.5e+07, 5.1e+07, 5.6e+07, 5.6e+07, 5.9e+07, 6e+07,
6e+07, 6e+07, 6.4e+07, 6.5e+07, 7.5e+07, 7.3e+07, 7.4e+07,
8e+07, 8.7e+07, 9.1e+07, 9.2e+07, 9.6e+07, 1.09e+08, 1.08e+08,
1.23e+08, 1.29e+08, 1.33e+08, 1.43e+08, 1.27e+08, 1.27e+08,
1.23e+08, 1.21e+08, 1.3e+08)), .Names = c("Date", "Value"
), row.names = c(NA, -29L), class = "data.frame")
a <- seq(as.Date(tail(z, 1)$Date), by="month", length=5)
a <- data.frame(Date = a)
z.lm <- lm(Value ~ Date, data=x)
z.pre<-predict(z.lm, newdata=a)
我可以这样绘制 z 数据: 这有效:
plot(z$Date, z$Value, type="l", col="blue",
xlim=(c(as.Date(head(x,1)$Date)), c(as.Date(tail(a,1)$Date)), xaxt="n"))
axis(1, z$Date, format(z$Date, "%b %Y"), cex.axis = .7)
当我尝试这样绘制预测值时:
lines(z.pre, col="red")
我没有收到错误,但我没有看到添加到原始图中的红线图。
有任何想法吗?