diff --git a/R/plot.R b/R/plot.R index 84aef0bb6..eff23634b 100644 --- a/R/plot.R +++ b/R/plot.R @@ -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) { diff --git a/tests/testthat/test-plot_predictions.R b/tests/testthat/test-plot_predictions.R index c5400179e..74537fb5e 100644 --- a/tests/testthat/test-plot_predictions.R +++ b/tests/testthat/test-plot_predictions.R @@ -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) +})