From 57d58edd064e6272e82f8836cff78144323ac24e Mon Sep 17 00:00:00 2001 From: Hugo Gruson Date: Tue, 23 Nov 2021 13:00:17 +0100 Subject: [PATCH] Pass range to sample_to_range_long() Fix #151 --- R/plot.R | 1 + .../many-quantiles-from-sample.svg | 1557 +++++++++++++++++ .../plot_predictions/many-quantiles.svg | 1557 +++++++++++++++++ ...oint-forecasts.svg => point-forecasts.svg} | 2 +- tests/testthat/test-plot_predictions.R | 20 +- 5 files changed, 3134 insertions(+), 3 deletions(-) create mode 100644 tests/testthat/_snaps/plot_predictions/many-quantiles-from-sample.svg create mode 100644 tests/testthat/_snaps/plot_predictions/many-quantiles.svg rename tests/testthat/_snaps/plot_predictions/{plot-predictions-point-forecasts.svg => point-forecasts.svg} (99%) diff --git a/R/plot.R b/R/plot.R index eff23634b..da272b3fe 100644 --- a/R/plot.R +++ b/R/plot.R @@ -701,6 +701,7 @@ plot_predictions <- function(data = NULL, colnames <- colnames(forecasts) if ("sample" %in% colnames) { forecasts <- scoringutils::sample_to_range_long(forecasts, + range = range, keep_quantile_col = FALSE) } else if ("quantile" %in% colnames) { forecasts <- scoringutils::quantile_to_range_long(forecasts, diff --git a/tests/testthat/_snaps/plot_predictions/many-quantiles-from-sample.svg b/tests/testthat/_snaps/plot_predictions/many-quantiles-from-sample.svg new file mode 100644 index 000000000..8eec6ce69 --- /dev/null +++ b/tests/testthat/_snaps/plot_predictions/many-quantiles-from-sample.svg @@ -0,0 +1,1557 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Scotland + + + + + + + + + + +Deaths + + + + + + + + + + + + + + + + + + + +Wales + + + + + + + + + + +Deaths + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Northern Ireland + + + + + + + + + + +Deaths + + + + + + + + + + + + + + + + + + + +Scotland + + + + + + + + + + +Total beds occupied + + + + + + + + + + + + + + + + + + + +Scotland + + + + + + + + + + +ICU beds occupied + + + + + + + + + + + + + + + + + + + +Scotland + + + + + + + + + + +Hospital admissions + + + + + + + + + + + + + + + + + + + +England + + + + + + + + + + +Total beds occupied + + + + + + + + + + + + + + + + + + + +England + + + + + + + + + + +Hospital admissions + + + + + + + + + + + + + + + + + + + +England + + + + + + + + + + +Deaths + + + + + + + + + + + + + + + + + + + +Northern Ireland + + + + + + + + + + +Hospital admissions + + + + + + + + + +May 01 +May 15 +Jun 01 +Jun 15 +Jul 01 + + + + + +May 01 +May 15 +Jun 01 +Jun 15 +Jul 01 + + + + + +May 01 +May 15 +Jun 01 +Jun 15 +Jul 01 + + + + + +May 01 +May 15 +Jun 01 +Jun 15 +Jul 01 +0 +5 +10 +15 +20 + + + + + +10 +20 +30 +40 +50 + + + + + +100 +200 +300 +400 + + + + +0 +25 +50 +75 + + + + +400 +600 +800 +1000 + + + + +500 +700 +900 +1100 +1300 + + + + + +5 +10 +15 +20 + + + + +2000 +4000 +6000 +8000 +10000 + + + + + +0.0 +2.5 +5.0 +7.5 + + + + +0 +10 +20 +30 +40 + + + + + +value_date +True and predicted values + +range + + + + + + + + + + + + +10 +20 +30 +40 +50 +60 + + + + + + + + + +actual +median +many_quantiles_from_sample + + diff --git a/tests/testthat/_snaps/plot_predictions/many-quantiles.svg b/tests/testthat/_snaps/plot_predictions/many-quantiles.svg new file mode 100644 index 000000000..d173f7dbc --- /dev/null +++ b/tests/testthat/_snaps/plot_predictions/many-quantiles.svg @@ -0,0 +1,1557 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Scotland + + + + + + + + + + +Deaths + + + + + + + + + + + + + + + + + + + +Wales + + + + + + + + + + +Deaths + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Northern Ireland + + + + + + + + + + +Deaths + + + + + + + + + + + + + + + + + + + +Scotland + + + + + + + + + + +Total beds occupied + + + + + + + + + + + + + + + + + + + +Scotland + + + + + + + + + + +ICU beds occupied + + + + + + + + + + + + + + + + + + + +Scotland + + + + + + + + + + +Hospital admissions + + + + + + + + + + + + + + + + + + + +England + + + + + + + + + + +Total beds occupied + + + + + + + + + + + + + + + + + + + +England + + + + + + + + + + +Hospital admissions + + + + + + + + + + + + + + + + + + + +England + + + + + + + + + + +Deaths + + + + + + + + + + + + + + + + + + + +Northern Ireland + + + + + + + + + + +Hospital admissions + + + + + + + + + +May 01 +May 15 +Jun 01 +Jun 15 +Jul 01 + + + + + +May 01 +May 15 +Jun 01 +Jun 15 +Jul 01 + + + + + +May 01 +May 15 +Jun 01 +Jun 15 +Jul 01 + + + + + +May 01 +May 15 +Jun 01 +Jun 15 +Jul 01 +0 +5 +10 +15 +20 + + + + + +10 +20 +30 +40 +50 + + + + + +100 +200 +300 +400 + + + + +0 +25 +50 +75 + + + + +400 +600 +800 +1000 + + + + +500 +700 +900 +1100 +1300 + + + + + +5 +10 +15 +20 + + + + +2000 +4000 +6000 +8000 +10000 + + + + + +0.0 +2.5 +5.0 +7.5 + + + + +0 +10 +20 +30 +40 + + + + + +value_date +True and predicted values + +range + + + + + + + + + + + + +10 +20 +30 +40 +50 +60 + + + + + + + + + +actual +median +many_quantiles + + diff --git a/tests/testthat/_snaps/plot_predictions/plot-predictions-point-forecasts.svg b/tests/testthat/_snaps/plot_predictions/point-forecasts.svg similarity index 99% rename from tests/testthat/_snaps/plot_predictions/plot-predictions-point-forecasts.svg rename to tests/testthat/_snaps/plot_predictions/point-forecasts.svg index 8a368e86f..3ad96c646 100644 --- a/tests/testthat/_snaps/plot_predictions/plot-predictions-point-forecasts.svg +++ b/tests/testthat/_snaps/plot_predictions/point-forecasts.svg @@ -935,6 +935,6 @@ actual median -plot_predictions_point_forecasts +point_forecasts diff --git a/tests/testthat/test-plot_predictions.R b/tests/testthat/test-plot_predictions.R index 74537fb5e..df6016223 100644 --- a/tests/testthat/test-plot_predictions.R +++ b/tests/testthat/test-plot_predictions.R @@ -13,7 +13,7 @@ test_that("plot_predictions() works with point forecasts", { facet_formula = geography ~ value_desc ) - vdiffr::expect_doppelganger('plot_predictions_point_forecasts', p) + vdiffr::expect_doppelganger('point_forecasts', p) }) @@ -32,5 +32,21 @@ test_that("plot_predictions() can handle an arbitrary number of quantiles", { range = c(0, 10, 20, 30, 40, 50, 60) ) - vdiffr::expect_doppelganger('plot_predictions_many_quantiles', p) + vdiffr::expect_doppelganger('many_quantiles', p) + + example1 <- scoringutils::continuous_example_data + + p2 <- scoringutils::plot_predictions( + example1, 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"'), + facet_formula = geography ~ value_desc, + range = c(0, 50, 90, 95) + ) + + vdiffr::expect_doppelganger('many_quantiles_from_sample', p) }) + +