Skip to content

Commit 77e684b

Browse files
committed
docs+lint: add arg checking and doc variables in autoplot
1 parent e66e75f commit 77e684b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

R/autoplot.R

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@ ggplot2::autoplot
2020
#' @param .levels A numeric vector of levels to plot for any prediction bands.
2121
#' More than 3 levels begins to be difficult to see.
2222
#' @param ... Ignored
23+
#' @param .color_by A character string indicating how to color the data. See
24+
#' `epiprocess::autoplot.epi_df()` for more details.
25+
#' @param .facet_by A character string indicating how to facet the data. See
26+
#' `epiprocess::autoplot.epi_df()` for more details.
2327
#' @param .base_color If available, prediction bands will be shown with this
2428
#' color.
2529
#' @param .point_pred_color If available, point forecasts will be shown with this
2630
#' color.
31+
#' @param .max_facets The maximum number of facets to show. If the number of
32+
#' facets is greater than this value, only the top facets will be shown.
2733
#'
2834
#' @name autoplot-epipred
2935
#' @examples
@@ -91,6 +97,9 @@ autoplot.epi_workflow <- function(
9197
.max_facets = Inf) {
9298
rlang::check_dots_empty()
9399
arg_is_probabilities(.levels)
100+
rlang::arg_match(.color_by)
101+
rlang::arg_match(.facet_by)
102+
94103
if (!workflows::is_trained_workflow(object)) {
95104
cli::cli_abort(c(
96105
"Can't plot an untrained {.cls epi_workflow}.",
@@ -197,8 +206,6 @@ autoplot.epi_workflow <- function(
197206
bp
198207
}
199208

200-
201-
202209
#' @export
203210
#' @rdname autoplot-epipred
204211
autoplot.canned_epipred <- function(
@@ -209,6 +216,9 @@ autoplot.canned_epipred <- function(
209216
.point_pred_color = "orange",
210217
.max_facets = Inf) {
211218
rlang::check_dots_empty()
219+
rlang::arg_match(.color_by)
220+
rlang::arg_match(.facet_by)
221+
212222
ewf <- object$epi_workflow
213223
predictions <- object$predictions %>%
214224
dplyr::rename(time_value = target_date)
@@ -283,7 +293,6 @@ plot_bands <- function(
283293
base_plot
284294
}
285295

286-
287296
find_level <- function(x) {
288297
unique((x < .5) * (1 - 2 * x) + (x > .5) * (1 - 2 * (1 - x)))
289298
}

0 commit comments

Comments
 (0)