为什么在出版物“Forecasting:原则与实践”不起作用?

fd3cxomn  于 2022-12-06  发布在  其他
关注(0)|答案(1)|浏览(101)

我正在阅读出版物 Forecasting:《原理与实践》 作者:Hyndman和Athanasopoulos(https://otexts.com/fpp3/time-plots.html),并且我无法使其中引用的autoplot()函数工作。我假设autoplot()是从预测包派生的,但是正如您在下面的代码中所看到的,我还摆弄了ggplot 2和ggfortify包,这两个包都不工作。当我尝试预测包时,得到的错误是“***forecast::autoplot()中出错:!<tbl_ts>自动绘图不支持类的对象。***”
如何让这个autoplot()函数工作呢?
下面是我试图模仿的出版物的autoplot()输出:

代码(在本例中,我尝试使用forecast::autoplot(...)进行预测包;还要注意,安装TSIBLEDATA包提供了在该示例中使用的“ANSETT”数据):

library(dplyr)
library(tsibble)
library(tsibbledata)
library(forecast)
library(ggplot2)
library(ggfortify)

melsyd_economy <- ansett %>%
  filter(Airports == "MEL-SYD", Class == "Economy") %>%
  mutate(Passengers = Passengers/1000)

forecast::autoplot(melsyd_economy, Passengers) +
  labs(title = "Ansett airlines economy class",
       subtitle = "Melbourne-Sydney",
       y = "Passengers ('000)")
oxiaedzo

oxiaedzo1#

tsibble s的autoplot方法来自fabletools套件。请参阅Plot time series from a tsibble

library(dplyr)
library(ggplot2)
library(tsibbledata)
library(fabletools)

melsyd_economy <- ansett %>%
  filter(Airports == "MEL-SYD", Class == "Economy") %>%
  mutate(Passengers = Passengers / 1000)

autoplot(melsyd_economy, Passengers) +
  labs(
    title = "Ansett airlines economy class",
    subtitle = "Melbourne-Sydney",
    y = "Passengers ('000)"
  )

相关问题