Skip to content

Commit

Permalink
Allow plotting of an arbitrary number of quantiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisaloo committed Nov 23, 2021
1 parent fb80e8d commit 07b40d0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
7 changes: 3 additions & 4 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -717,12 +717,11 @@ plot_predictions <- function(data = NULL,
intervals[, quantile := NULL]
}

pal <- grDevices::colorRampPalette(c("steelblue3", "lightskyblue1"))

plot <- ggplot2::ggplot(data = data, aes(x = !!ggplot2::sym(x))) +
ggplot2::scale_colour_manual("",values = c("black", "steelblue4")) +
ggplot2::scale_fill_manual("range", values = c("steelblue3",
"lightskyblue3",
"lightskyblue2",
"lightskyblue1")) +
ggplot2::scale_fill_manual(name = "range", values = pal(length(range))) +
ggplot2::theme_light()

if (nrow(intervals) != 0) {
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-plot_predictions.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,21 @@ test_that("plot_predictions() works with point forecasts", {
vdiffr::expect_doppelganger('plot_predictions_point_forecasts', p)

})

test_that("plot_predictions() can handle an arbitrary number of quantiles", {

example2 <- scoringutils::range_example_data_long

p <- scoringutils::plot_predictions(
example2, x = "value_date",
filter_truth = list('value_date <= "2020-06-22"',
'value_date > "2020-05-01"'),
filter_forecasts = list("model == 'SIRCOVID'",
'creation_date == "2020-06-22"'),
allow_truth_without_pred = TRUE,
facet_formula = geography ~ value_desc,
range = c(0, 10, 20, 30, 40, 50, 60)
)

vdiffr::expect_doppelganger('plot_predictions_many_quantiles', p)
})

0 comments on commit 07b40d0

Please sign in to comment.