1

由于我们不能scale_x_date(){tsibble}对象一起使用,那么更改中断、标签等的方法是什么?

# metapackage
library(fpp3)

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

# plot
autoplot(melsyd_economy, Passengers) +
  labs(title = "Ansett airlines economy class",
       subtitle = "Melbourne-Sydney",
       y = "Passengers ('000)") +
  scale_x_date(date_labels = "%Y", date_breaks = "2 year")
4

1 回答 1

1

问题不是tsibble,问题是你的Week变量不是 class Date。但是您可以将其转换为 aDate以使其scale_x_date工作:

# metapackage
library(fpp3)

# data
melsyd_economy <- ansett %>%
  filter(Airports == "MEL-SYD", Class == "Economy") %>%
  mutate(Passengers = Passengers/1000) %>% 
  mutate(Week = lubridate::as_date(Week))

# plot
autoplot(melsyd_economy, Passengers) +
  labs(title = "Ansett airlines economy class",
       subtitle = "Melbourne-Sydney",
       y = "Passengers ('000)") +
  scale_x_date(date_labels = "%Y", date_breaks = "2 year")

于 2021-10-05T14:58:27.573 回答