autoplot-epipred | R Documentation |
epi_workflow
or canned_epipred
objectFor a fit workflow, the training data will be displayed, the response by
default. If predictions
is not NULL
then point and interval forecasts
will be shown as well. Unfit workflows will result in an error, (you
can simply call autoplot()
on the original epi_df
).
## S3 method for class 'epi_workflow'
autoplot(
object,
predictions = NULL,
.levels = c(0.5, 0.8, 0.9),
...,
.color_by = c("all_keys", "geo_value", "other_keys", ".response", "all", "none"),
.facet_by = c(".response", "other_keys", "all_keys", "geo_value", "all", "none"),
.base_color = "dodgerblue4",
.point_pred_color = "orange",
.max_facets = Inf
)
## S3 method for class 'canned_epipred'
autoplot(
object,
...,
.color_by = c("all_keys", "geo_value", "other_keys", ".response", "all", "none"),
.facet_by = c(".response", "other_keys", "all_keys", "geo_value", "all", "none"),
.base_color = "dodgerblue4",
.point_pred_color = "orange",
.max_facets = Inf
)
object |
An |
predictions |
A data frame with predictions. If |
.levels |
A numeric vector of levels to plot for any prediction bands. More than 3 levels begins to be difficult to see. |
... |
Ignored |
.color_by |
Which variables should determine the color(s) used to plot lines. Options include:
|
.facet_by |
Similar to |
.base_color |
If available, prediction bands will be shown with this color. |
.point_pred_color |
If available, point forecasts will be shown with this color. |
.max_facets |
Cut down of the number of facets displayed. Especially
useful for testing when there are many |
jhu <- covid_case_death_rates %>%
filter(time_value >= as.Date("2021-11-01"))
r <- epi_recipe(jhu) %>%
step_epi_lag(death_rate, lag = c(0, 7, 14)) %>%
step_epi_ahead(death_rate, ahead = 7) %>%
step_epi_lag(case_rate, lag = c(0, 7, 14)) %>%
step_epi_naomit()
f <- frosting() %>%
layer_residual_quantiles() %>%
layer_threshold(starts_with(".pred")) %>%
layer_add_target_date()
wf <- epi_workflow(r, linear_reg(), f) %>% fit(jhu)
autoplot(wf)
latest <- jhu %>% filter(time_value >= max(time_value) - 14)
preds <- predict(wf, latest)
autoplot(wf, preds, .max_facets = 4)
# ------- Show multiple horizons
p <- lapply(c(7, 14, 21, 28), function(h) {
r <- epi_recipe(jhu) %>%
step_epi_lag(death_rate, lag = c(0, 7, 14)) %>%
step_epi_ahead(death_rate, ahead = h) %>%
step_epi_lag(case_rate, lag = c(0, 7, 14)) %>%
step_epi_naomit()
ewf <- epi_workflow(r, linear_reg(), f) %>% fit(jhu)
forecast(ewf)
})
p <- do.call(rbind, p)
autoplot(wf, p, .max_facets = 4)
# ------- Plotting canned forecaster output
jhu <- covid_case_death_rates %>%
filter(time_value >= as.Date("2021-11-01"))
flat <- flatline_forecaster(jhu, "death_rate")
autoplot(flat, .max_facets = 4)
arx <- arx_forecaster(jhu, "death_rate", c("case_rate", "death_rate"),
args_list = arx_args_list(ahead = 14L)
)
autoplot(arx, .max_facets = 6)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.