I’m using the fpp3 framework (tsibble + fable + fabletools) to forecast time series data and plot the results with autoplot(). The code below is almost identical to the example from Forecasting: Principles and Practice (using aus_retail), but in my environment the legend background for the prediction intervals is solid black, instead of showing different fill colors for the intervals.
Here is a minimal reproducible example:
library(fpp3)
auscafe <- aus_retail |>
filter(stringr::str_detect(Industry, "Takeaway")) |>
summarise(Turnover = sum(Turnover))
train <- auscafe |>
filter(year(Month) <= 2013)
STLF <- decomposition_model(
STL(log(Turnover) ~ season(window = Inf)),
ETS(season_adjust ~ season("N"))
)
cafe_models <- train |>
model(
ets = ETS(Turnover),
stlf = STLF,
arima = ARIMA(log(Turnover))
) |>
mutate(combination = (ets + stlf + arima) / 3)
cafe_fc <- cafe_models |>
forecast(h = "5 years")
cafe_fc |>
autoplot(auscafe |> filter(year(Month) > 2008),
level = NULL) +
labs(y = "美元(十亿)",
title = "澳大利亚每月外出就餐支出",x="月份")+
scale_color_discrete(name="预测模型")
cafe_fc |> filter(Month == min(Month))
cafe_futures <- cafe_models |>
generate(h = "5 years", times = 1000) |>
as_tibble() |>
group_by(Month, .model) |>
summarise(
dist = distributional::dist_sample(list(.sim))
) |>
ungroup() |>
as_fable(index = Month, key = .model,
distribution = dist, response = "Turnover")
cafe_futures |>
filter(.model == "combination") |>
autoplot(auscafe |> filter(year(Month) > 2008)) +
labs(y = "美元(十亿)",
title = "澳大利亚每月外出就餐支出",x="月份")
The issue is with the last plot
Referred here by Forecasting: Principles and Practice, by Rob J Hyndman and George Athanasopoulos