Hi Rob and Mitch
Following the recent updates to 0.4.0 regarding both packages: distributional and fabletools, there's some differences in the consistencies between the plotting functions.
Below are 2 examples generating forecasts based on the data in fpp3:
(1) static
(2) dynamic
For static forecasts I previously used geom_hilo_ribbon, which has been deprecated and instead there's ggdist::stat_lineribbon or ggdist::geom_lineribbon.
I would like the stretch_tsibble static one-step ahead forecast graphs to be same as the default autoplot dynamic multistep ahead graphs.
The differences being for the static one-step ahead versus the default autoplot dynamic multistep ahead:
(a) Not exactly the same colour. What are the default autoplot dynamic multistep ahead colours?
(b) Being see through in colour, i.e. can see the grid in the background. How do I make the colours not see-through or opaque in plot_S?
(c) The level key on the RHS is 0.95 and 0.8 and both the same colour, whereas the default autoplot is 80% and 95% respectively and different colours.
i.e. How do I change plot_S to match plot_D?
#===============================
library(fpp3)
library(ggdist)
## ---- global economy--------------------------------------------------------
aus_economy <- global_economy |>
filter(Code == "AUS") |>
mutate(Population = Population / 1e6)
fc_st <- aus_economy |>
slice(-n()) |>
stretch_tsibble(.init = 40) |>
model(ETS(log(Population))) |>
forecast(h = 1, point_forecast = lst(.mean = mean, .median = median), bootstrap = TRUE)
fc_st
Pop <- global_economy |>
filter(Code == "AUS") |>
mutate(Population = Population / 1e6) |>
select(Population)
plot_S <- fc_st |>
ggplot(aes(x = Year, ydist = Population)) +
stat_lineribbon(
.width = c(0.8, 0.95),
color = "blue",
fill = "blue",
alpha = 0.2,
show.legend = TRUE,
lwd = 0.1
) +
scale_fill_brewer() +
geom_line(aes(y = .mean), color = "blue", linetype = "solid") +
geom_line(aes(y = .median, color = "median"), color = "blue", linetype = "dotted") +
geom_line(data = Pop, aes(x = Year, y = Population)) +
theme(plot.title = element_text(hjust = 0.5)) +
theme(axis.text = element_text(size = 14)) +
theme(plot.caption = element_text(hjust = 0)) + # set the left align here
labs(caption = "bootstrapped residuals") +
ggtitle("Population\nYRECURSIVE Static one-step ahead Forecasts and Prediction Intervals ETS")
plot_S
#===============================
#Series for IS period
y <- Pop |> filter(Year >= '1960' & Year <= '1999')
#fit ETS
fit <- y |>
model('ets' = ETS(log(Population)))
fit
#dynamic forecasts
fc_D <- fit |>
forecast(h = 18, point_forecast = lst(.mean = mean, .median = median), bootstrap = TRUE)
fc_D
#dynamic forecasts & PI's
fcPI_D <- fc_D |> hilo()
fcPI_D
#fc_D fanchart
plot_D <- fc_D |>
autoplot(y) +
geom_line(aes(y = .median), col = "blue", data = fc_D, linetype = "dashed") +
geom_line(data = Pop, aes(x = Year, y = Population)) +
theme(plot.title = element_text(hjust = 0.5)) +
theme(axis.text = element_text(size = 14)) +
theme(plot.caption = element_text(hjust = 0)) + # set the left align here
labs(caption = "bootstrapped residuals") +
ggtitle("Population\nYRECURSIVE Dynamic h-steps ahead Forecasts and Prediction Intervals ETS")
plot_D
Also I have also noticed from the following:
#===============================
fit <- y |>
model(
naive = ARIMA(Population ~ 0 + pdq(0, 1, 0)), # NAIVE(value),
rw_drift = ARIMA(Population ~ 1 + pdq(0, 1, 0)) # RW(value ~ drift())
)
fit
fc_simple_D <- fit |>
forecast(h = 20, point_forecast = lst(.mean = mean), bootstrap = TRUE)
fc_simple_D
fc_simple_D |>
autoplot(tail(y, 20), point_forecast = lst(.mean = mean))
(i )The .model key on the RHS is blocked in colour, whereas they used to have a diagonal time line for each model, as here Key glyphs for legends — draw_key • ggplot2 (tidyverse.org). How do I get the timeseries key glyph in the default autoplot?
(ii) The new blocked colour(s) in the key are different to the actual fan(s) colours.
thanks,
Amarjit