-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathautoplot-epipred.Rd
122 lines (102 loc) · 3.83 KB
/
autoplot-epipred.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/autoplot.R
\name{autoplot-epipred}
\alias{autoplot-epipred}
\alias{autoplot.epi_workflow}
\alias{autoplot.canned_epipred}
\title{Automatically plot an \code{epi_workflow} or \code{canned_epipred} object}
\usage{
\method{autoplot}{epi_workflow}(
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
)
\method{autoplot}{canned_epipred}(
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
)
}
\arguments{
\item{object}{An \code{epi_workflow}}
\item{predictions}{A data frame with predictions. If \code{NULL}, only the
original data is shown.}
\item{.levels}{A numeric vector of levels to plot for any prediction bands.
More than 3 levels begins to be difficult to see.}
\item{...}{Ignored}
\item{.color_by}{Which variables should determine the color(s) used to plot
lines. Options include:
\itemize{
\item \code{all_keys} - the default uses the interaction of any key variables
including the \code{geo_value}
\item \code{geo_value} - \code{geo_value} only
\item \code{other_keys} - any available keys that are not \code{geo_value}
\item \code{.response} - the numeric variables (same as the y-axis)
\item \code{all} - uses the interaction of all keys and numeric variables
\item \code{none} - no coloring aesthetic is applied
}}
\item{.facet_by}{Similar to \code{.color_by} except that the default is to
display the response.}
\item{.base_color}{If available, prediction bands will be shown with this
color.}
\item{.point_pred_color}{If available, point forecasts will be shown with
this color.}
\item{.max_facets}{Cut down of the number of facets displayed. Especially
useful for testing when there are many \code{geo_value}'s or keys.}
}
\description{
For a fit workflow, the training data will be displayed, the response by
default. If \code{predictions} is not \code{NULL} then point and interval forecasts
will be shown as well. Unfit workflows will result in an error, (you
can simply call \code{autoplot()} on the original \code{epi_df}).
}
\examples{
library(dplyr)
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)
}