Home > Mobile >  Why is the autoplot function giving an error in this example from publication "Forecasting: Pri
Why is the autoplot function giving an error in this example from publication "Forecasting: Pri

Time:12-01

I am working through section 2.2 "Time Plots" of publication Forecasting: Principles and Practice by Hyndman and Athanasopoulos (enter image description here

Code (in this example I was trying forecast package by using forecast::autoplot(...); further note that installing the tsibbledata package provides the "ansett" data used in this example):

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)")

CodePudding user response:

The autoplot method for tsibbles is from the fabletools package. See 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)"
  )

  • Related