首页 > 解决方案 > 使用自动绘图标记值

问题描述

我使用包创建了一个时间序列模型forecast使用autoplot.

require(ggplot2)
require(forecast)
y <- hw(AirPassengers, h=10, seasonal="multiplicative")
autoplot(y, main="Air passengers - Holt seasonal") +
  autolayer(y, series="multiplicative", PI=FALSE)

具有未来预测值的时间序列

但是,我希望像这样标记观察结果: ggplot 折线图中的变量标签位置,但仅用于预测值。我理解该子句应该是,geom_text( aes(label = ?) )但是由于y传递给的对象autoplot是 ats我不确定如何引用?

我已经诉诸as.numeric(y[["mean"]])但得到了错误Error: geom_text requires the following missing aesthetics: x, y,因为这是一个向量并且缺少日期?

谢谢你。

标签: rggplot2

解决方案


推荐阅读