1

A quick reprex from the book's website:

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

enter image description here

Note the x-axis has unusually formatting based on the week index. What I would like to do is adjust this, such as showing the year only (1989, 1990, 1991, etc.)

Blake Shurtz
  • 321
  • 3
  • 13

1 Answers1

1

The Week column in the tibble is yearweek class.

R> class(melsyd_economy$Week)
[1] "yearweek"   "vctrs_vctr"

You can use scale_x_yearweek from tsibble package (contained within fpp3) with autoplot and design the x-axis label you want. Here's an example with just year:

library(fpp3)

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)",
       x = "Year") +
  scale_x_yearweek(date_labels = "%Y")

Plot

autoplot with specified date_labels using scale_x_yearweek

Ben
  • 28,684
  • 5
  • 23
  • 45