Skip to content

Commit

Permalink
update plot documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosbosse committed Feb 3, 2021
1 parent b75e469 commit 7e5880e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
12 changes: 8 additions & 4 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,12 @@ score_heatmap <- function(scores,
#' \code{NULL}
#' @param scales scales argument that gets passed down to ggplot. Only necessary
#' if you make use of facetting. Default is "free_y"
#' @param allow_truth_without_pred logical, whether or not
#' to allow instances where there is truth data, but no forecast. If `FALSE`
#' (the default), these get filtered out.
#' @param xlab Label for the x-axis. Default is the variable name on the x-axis
#' @param ylab Label for the y-axis. Default is "True and predicted values"
#' @param verbose print out additional helpful messages (default is TRUE)
#' @return ggplot object with a plot of true vs predicted values
#' @importFrom ggplot2 ggplot scale_colour_manual scale_fill_manual
#' facet_wrap facet_grid
Expand All @@ -604,23 +608,22 @@ score_heatmap <- function(scores,
#' allow_truth_without_pred = TRUE,
#' facet_formula = geography ~ value_desc)


plot_predictions <- function(data,
plot_predictions <- function(data = NULL,
forecasts = NULL,
truth_data = NULL,
merge_by = NULL,
x = "date",
filter_truth = list(),
filter_forecasts = list(),
filter_both = list(),
add_truth_data = NULL,
range = c(0, 50, 90),
facet_formula = NULL,
facet_wrap_or_grid = "facet_wrap",
scales = "free_y",
allow_truth_without_pred = FALSE,
xlab = x,
ylab = "True and predicted values") {
ylab = "True and predicted values",
verbose = TRUE) {

# preparations ---------------------------------------------------------------
# check data argument is provided
Expand All @@ -638,6 +641,7 @@ plot_predictions <- function(data,
}
}

# split truth data and forecasts in order to apply different filtering
truth_data <- data.table::copy(data)[!is.na(true_value)]
forecasts <- data.table::copy(data)[!is.na(prediction)]

Expand Down
3 changes: 2 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ geom_mean_helper <- function(x) {
}


globalVariables(c(".",
globalVariables(c("..index",
".",
".SD",
"ae_point",
"aem",
Expand Down
21 changes: 17 additions & 4 deletions man/plot_predictions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions vignettes/scoringutils.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,14 @@ Using an appropriate level of summary, we can easily use the output for visualis
# creation_date <= "2020-06-29" &
# value_desc == "Deaths"]
scoringutils::plot_predictions(data = data,
filter_both = list("geography == 'England'",
"value_desc == 'Deaths'"),
filter_forecasts = list("creation_date == '2020-06-29'"),
filter_truth = list("as.Date(value_date) < '2020-06-22'"),
scoringutils::plot_predictions(data = data,
filter_both = list("geography == 'England'"),
filter_forecasts = list("creation_date == '2020-07-06'"),
filter_truth = list("as.Date(value_date) <= '2020-07-06'"),
x = "value_date",
range = c(0, 50, 90),
scale = "fixed",
facet_formula = ~ model)
scale = "free",
facet_formula = value_desc ~ model)
```


Expand Down

0 comments on commit 7e5880e

Please sign in to comment.