diff --git a/NAMESPACE b/NAMESPACE index c4e3a3ad2..02ff443b3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,8 @@ # Generated by roxygen2: do not edit by hand S3method(plot,scoringutils_available_forecasts) +S3method(plot,scoringutils_correlation) +S3method(plot,scoringutils_pairwise) S3method(print,scoringutils_check) export(abs_error) export(add_coverage) diff --git a/NEWS.md b/NEWS.md index a3104d27d..86956fdd5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,11 +3,18 @@ This minor update addresses comments made by review from the Journal of Statistical Software (see preprint of the manuscript [here](https://arxiv.org/abs/2205.07090)). ## Package updates -- changes to `avail_forecasts()` and `plot_avail_forecasts()`: - - the function `avail_forecasts()` was renamed to `available_forecasts()` for consistency with `available_metrics()`. The old function, `avail_forecasts()` is still available as an alias, but will be removed in the future. - - For clarity, the output column in `avail_forecasts()` was renamed from "Number forecasts" to "count". - - `available_forecasts()` now also displays combinations where there are 0 forecasts, instead of silently dropping corresponding rows. - - `plot_avail_forecasts()` has been deprecated in favour of an S3 method for `plot()`. An alias is still available, but will be removed in the future. + +### changes to `avail_forecasts()` and `plot_avail_forecasts()`: +- the function `avail_forecasts()` was renamed to `available_forecasts()` for consistency with `available_metrics()`. The old function, `avail_forecasts()` is still available as an alias, but will be removed in the future. +- For clarity, the output column in `avail_forecasts()` was renamed from "Number forecasts" to "count". +- `available_forecasts()` now also displays combinations where there are 0 forecasts, instead of silently dropping corresponding rows. + +### New S3 plotting methods +- `plot_avail_forecasts()` has been deprecated in favour of an S3 method for `plot()`. An alias is still available, but will be removed in the future. +- `plot_correlation()` has been deprecated in favour of an S3 method for `plot()`. An alias is still available, but will be removed in the future. +- `plot_pairwise_comparison()` has been deprecated in favour of an S3 method for `plot()`. An alias is still available, but will be removed in the future. + +### other - the deprecated `..density..` was replaced with `after_stat(density)` in ggplot calls. - files ending in ".Rda" were renamed to ".rds" where appropriate when used together with `saveRDS()` or readRDS()`. diff --git a/R/avail_forecasts.R b/R/avail_forecasts.R index b34180ca9..672fe8794 100644 --- a/R/avail_forecasts.R +++ b/R/avail_forecasts.R @@ -20,11 +20,14 @@ #' that a single forecast only gets counted once. #' #' @return A data.table with columns as specified in `by` and an additional -#' column "count" with the number of forecasts. +#' column "count" with the number of forecasts. In addition the output has class +#' `scoringutils_available_forecasts` and can e.g. be visualised +#' using [plot()] (which dispatches [plot.scoringutils_available_forecasts()]. #' #' @inheritParams score #' @importFrom data.table .I .N nafill #' @export +#' @seealso [plot.scoringutils_available_forecasts()] #' @keywords check-forecasts #' @examples #' data.table::setDTthreads(1) # only needed to avoid issues on CRAN diff --git a/R/correlations.R b/R/correlations.R index 5b8233576..580176e82 100644 --- a/R/correlations.R +++ b/R/correlations.R @@ -2,20 +2,25 @@ #' #' @description #' Calculate the correlation between different metrics for a data.frame of -#' scores as produced by [score()]. +#' scores as produced by [score()]. You can visualise results #' #' @param metrics A character vector with the metrics to show. If set to #' `NULL` (default), all metrics present in `scores` will #' be shown #' @inheritParams pairwise_comparison -#' @return A data.table with correlations for the different metrics +#' @return A data.table with correlations for the different metrics. In addition, +#' the output is of class `scoringutils_correlation` and can e.g. be visualised +#' using [plot()] (which dispatches [plot.scoringutils_correlation()]. +#' #' @importFrom data.table setDT #' @importFrom stats cor na.omit #' @export #' @keywords scoring +#' @seealso [plot.scoringutils_correlation()] #' @examples #' scores <- score(example_quantile) -#' correlation(scores) +#' corrs <- correlation(scores) +#' plot(corrs) correlation <- function(scores, metrics = NULL) { metrics <- check_metrics(metrics) @@ -49,6 +54,8 @@ correlation <- function(scores, keep.rownames = TRUE )[, metric := rn][, rn := NULL] + class(correlations) <- c("scoringutils_correlation", class(correlations)) + return(correlations[]) } diff --git a/R/pairwise-comparisons.R b/R/pairwise-comparisons.R index efce335eb..ec94bcaba 100644 --- a/R/pairwise-comparisons.R +++ b/R/pairwise-comparisons.R @@ -43,7 +43,9 @@ #' model against which to compare other models. #' @param ... additional arguments for the comparison between two models. See #' [compare_two_models()] for more information. -#' @return A ggplot2 object with a coloured table of summarised scores +#' @return A data.table with pairwise comparisons. In addition, the output is +#' of class `scoringutils_pairwise` and can be visualised using [plot()] (which +#' dispatches [plot.scoringutils_pairwise()]. #' @importFrom data.table as.data.table data.table setnames copy #' @importFrom stats sd rbinom wilcox.test p.adjust #' @importFrom utils combn @@ -51,6 +53,7 @@ #' @author Nikos Bosse \email{nikosbosse@@gmail.com} #' @author Johannes Bracher, \email{johannes.bracher@@kit.edu} #' @keywords scoring +#' @seealso [plot.scoringutils_pairwise()] #' @examples #' data.table::setDTthreads(1) # only needed to avoid issues on CRAN #' @@ -58,7 +61,7 @@ #' pairwise <- pairwise_comparison(scores, by = "target_type") #' #' library(ggplot2) -#' plot_pairwise_comparison(pairwise, type = "mean_scores_ratio") + +#' plot(pairwise, type = "mean_scores_ratio") + #' facet_wrap(~target_type) pairwise_comparison <- function(scores, @@ -139,6 +142,8 @@ pairwise_comparison <- function(scores, out <- data.table::rbindlist(results) + class(out) <- c("scoringutils_pairwise", class(out)) + return(out[]) } diff --git a/R/plot.R b/R/plot.R index cf6607b0c..6e97901f4 100644 --- a/R/plot.R +++ b/R/plot.R @@ -19,6 +19,7 @@ #' @importFrom ggplot2 ggplot aes element_blank element_text labs coord_cartesian coord_flip #' @importFrom data.table setDT melt #' @importFrom stats sd +#' @family plotting functions #' @export #' #' @examples @@ -148,6 +149,7 @@ plot_score_table <- function(scores, #' scale_fill_discrete #' theme theme_light unit guides guide_legend .data #' @export +#' @family plotting functions #' @examples #' library(ggplot2) #' scores <- score(example_quantile) @@ -233,6 +235,7 @@ plot_wis <- function(scores, #' @importFrom ggplot2 ggplot aes aes geom_point geom_line #' expand_limits theme theme_light element_text scale_color_continuous labs #' @export +#' @family plotting functions #' @examples #' library(ggplot2) #' scores <- score(example_quantile) @@ -296,6 +299,7 @@ plot_ranges <- function(scores, #' @importFrom ggplot2 ggplot aes geom_tile geom_text .data #' scale_fill_gradient2 labs element_text coord_cartesian #' @export +#' @family plotting functions #' @examples #' scores <- score(example_quantile) #' scores <- summarise_scores(scores, by = c("model", "target_type", "range")) @@ -352,6 +356,7 @@ plot_heatmap <- function(scores, #' @importFrom data.table dcast #' @importFrom ggdist geom_lineribbon #' @export +#' @family plotting functions #' @examples #' library(ggplot2) #' library(magrittr) @@ -581,6 +586,7 @@ make_na <- make_NA #' facet_wrap facet_grid geom_polygon #' @importFrom data.table dcast #' @export +#' @family plotting functions #' @examples #' data.table::setDTthreads(1) # only needed to avoid issues on CRAN #' scores <- score(example_quantile) @@ -637,6 +643,7 @@ plot_interval_coverage <- function(scores, #' scale_y_continuous #' @importFrom data.table dcast #' @export +#' @family plotting functions #' @examples #' scores <- score(example_quantile) #' scores <- summarise_scores(scores, by = c("model", "quantile")) @@ -687,18 +694,22 @@ plot_quantile_coverage <- function(scores, return(p2) } + #' @title Plot Heatmap of Pairwise Comparisons #' #' @description #' Creates a heatmap of the ratios or pvalues from a pairwise comparison #' between models #' -#' @param comparison_result A data.frame as produced by +#' @param x An S3 object as produced by #' [pairwise_comparison()] #' @param type character vector of length one that is either #' "mean_scores_ratio" or "pval". This denotes whether to #' visualise the ratio or the p-value of the pairwise comparison. #' Default is "mean_scores_ratio". +#' @inheritParams print.scoringutils_check +#' @return A data.table with pairwise comparisons. In addition, the output is +#' of class `scoringutils_pairwise` and can be visualised using [plot()]. #' @importFrom ggplot2 ggplot aes geom_tile geom_text labs coord_cartesian #' scale_fill_gradient2 theme_light element_text #' @importFrom data.table as.data.table setnames rbindlist @@ -706,16 +717,18 @@ plot_quantile_coverage <- function(scores, #' @importFrom ggplot2 labs coord_cartesian facet_wrap facet_grid theme #' element_text element_blank #' @export +#' @family plotting functions #' @examples #' library(ggplot2) #' scores <- score(example_quantile) #' pairwise <- pairwise_comparison(scores, by = "target_type") -#' plot_pairwise_comparison(pairwise, type = "mean_scores_ratio") + +#' plot(pairwise, type = "mean_scores_ratio") + #' facet_wrap(~target_type) -plot_pairwise_comparison <- function(comparison_result, - type = c("mean_scores_ratio", "pval")) { - comparison_result <- data.table::as.data.table(comparison_result) +plot.scoringutils_pairwise <- function(x, + type = c("mean_scores_ratio", "pval"), + ...) { + comparison_result <- data.table::as.data.table(x) comparison_result[, model := reorder(model, -relative_skill)] levels <- levels(comparison_result$model) @@ -810,6 +823,28 @@ plot_pairwise_comparison <- function(comparison_result, } +#' @title `r lifecycle::badge("deprecated")` Plot Heatmap of Pairwise Comparisons +#' +#' @description +#' Deprecated version of [plot.scoringutils_pairwise()] +#' +#' @param comparison_result A data.frame as produced by +#' [pairwise_comparison()] +#' @inherit plot.scoringutils_pairwise +#' @export +plot_pairwise_comparison <- function(comparison_result, + type = c("mean_scores_ratio", "pval")) { + + lifecycle::deprecate_warn( + "1.2.2", "plot_pairwise_comparison()", + "plot()" + ) + + plot.scoringutils_pairwise(x = comparison_result, + type = type) +} + + #' @title PIT Histogram #' #' @description @@ -833,6 +868,7 @@ plot_pairwise_comparison <- function(comparison_result, #' @importFrom stats as.formula #' @importFrom ggplot2 geom_col #' @importFrom stats density +#' @family plotting functions #' @return vector with the scoring values #' @examples #' data.table::setDTthreads(1) # only needed to avoid issues on CRAN @@ -937,6 +973,7 @@ plot_pit <- function(pit, return(hist) } + #' @title Visualise Where Forecasts Are Available #' #' @description @@ -958,6 +995,7 @@ plot_pit <- function(pit, #' geom_tile scale_fill_gradient .data #' @importFrom data.table dcast .I .N #' @export +#' @family plotting functions #' @examples #' library(ggplot2) #' available_forecasts <- available_forecasts( @@ -1047,33 +1085,32 @@ plot_avail_forecasts <- function(available_forecasts, } - - #' @title Plot Correlation Between Metrics -#' #' @description #' Plots a heatmap of correlations between different metrics #' -#' @param correlations A data.table of correlations between scores as produced -#' by [correlation()]. +#' @param x An S3 object with correlations between scores as produced by +#' [correlation()]. +#' @inheritParams print.scoringutils_check #' @return A ggplot2 object showing a coloured matrix of correlations #' between metrics #' @importFrom ggplot2 ggplot geom_tile geom_text aes scale_fill_gradient2 #' element_text labs coord_cartesian theme element_blank #' @importFrom data.table setDT melt #' @export +#' @family plotting functions #' @examples #' scores <- score(example_quantile) #' correlations <- correlation( #' summarise_scores(scores) #' ) -#' plot_correlation(correlations) +#' plot(correlations) -plot_correlation <- function(correlations) { +plot.scoringutils_correlation <- function(x, ...) { - metrics <- names(correlations)[names(correlations) %in% available_metrics()] + metrics <- names(x)[names(x) %in% available_metrics()] - lower_triangle <- get_lower_tri(correlations[, .SD, .SDcols = metrics]) + lower_triangle <- get_lower_tri(x[, .SD, .SDcols = metrics]) rownames(lower_triangle) <- colnames(lower_triangle) # get plot data.frame @@ -1111,6 +1148,23 @@ plot_correlation <- function(correlations) { return(plot) } + +#' @title `r lifecycle::badge("deprecated")` Plot Correlation Between Metrics +#' +#' @description +#' Deprecated version of [plot.scoringutils_correlation()] for compatibility. +#' @param correlations A data.table with correalations as produced by +#' [correlation()] +#' @export +plot_correlation <- function(correlations) { + lifecycle::deprecate_warn( + "1.2.2", "plot_correlation()", + "plot()" + ) + plot.scoringutils_correlation(x = correlations) +} + + #' @title Scoringutils ggplot2 theme #' #' @description diff --git a/inst/manuscript/R/00-standalone-Figure-replication.R b/inst/manuscript/R/00-standalone-Figure-replication.R index f6d801697..297b0c8b7 100644 --- a/inst/manuscript/R/00-standalone-Figure-replication.R +++ b/inst/manuscript/R/00-standalone-Figure-replication.R @@ -660,4 +660,4 @@ correlations |> glimpse() correlations |> - plot_correlation() + plot() diff --git a/inst/manuscript/manuscript.Rmd b/inst/manuscript/manuscript.Rmd index b0b14f728..c87026c91 100644 --- a/inst/manuscript/manuscript.Rmd +++ b/inst/manuscript/manuscript.Rmd @@ -527,7 +527,7 @@ Using the function \fct{plot\_pairwise\_comparison} we can visualise the mean sc score(example_quantile) |> pairwise_comparison(by = c("model", "target_type"), baseline = "EuroCOVIDhub-baseline") |> - plot_pairwise_comparison() + + plot() + facet_wrap(~ target_type) ``` @@ -642,8 +642,7 @@ correlations <- example_quantile |> correlations |> glimpse() -correlations |> - plot_correlation() +plot(correlations) ``` ## Summary and discussion diff --git a/man/available_forecasts.Rd b/man/available_forecasts.Rd index a35e7d891..8e5217cd6 100644 --- a/man/available_forecasts.Rd +++ b/man/available_forecasts.Rd @@ -48,7 +48,9 @@ that a single forecast only gets counted once.} } \value{ A data.table with columns as specified in \code{by} and an additional -column "count" with the number of forecasts. +column "count" with the number of forecasts. In addition the output has class +\code{scoringutils_available_forecasts} and can e.g. be visualised +using \code{\link[=plot]{plot()}} (which dispatches \code{\link[=plot.scoringutils_available_forecasts]{plot.scoringutils_available_forecasts()}}. } \description{ Given a data set with forecasts, count the number of available forecasts @@ -64,4 +66,7 @@ available_forecasts(example_quantile, by = c("model", "target_type") ) } +\seealso{ +\code{\link[=plot.scoringutils_available_forecasts]{plot.scoringutils_available_forecasts()}} +} \keyword{check-forecasts} diff --git a/man/correlation.Rd b/man/correlation.Rd index 77de3a469..4e93d34bb 100644 --- a/man/correlation.Rd +++ b/man/correlation.Rd @@ -14,14 +14,20 @@ correlation(scores, metrics = NULL) be shown} } \value{ -A data.table with correlations for the different metrics +A data.table with correlations for the different metrics. In addition, +the output is of class \code{scoringutils_correlation} and can e.g. be visualised +using \code{\link[=plot]{plot()}} (which dispatches \code{\link[=plot.scoringutils_correlation]{plot.scoringutils_correlation()}}. } \description{ Calculate the correlation between different metrics for a data.frame of -scores as produced by \code{\link[=score]{score()}}. +scores as produced by \code{\link[=score]{score()}}. You can visualise results } \examples{ scores <- score(example_quantile) -correlation(scores) +corrs <- correlation(scores) +plot(corrs) +} +\seealso{ +\code{\link[=plot.scoringutils_correlation]{plot.scoringutils_correlation()}} } \keyword{scoring} diff --git a/man/pairwise_comparison.Rd b/man/pairwise_comparison.Rd index 4c14b975e..d94ec6e2e 100644 --- a/man/pairwise_comparison.Rd +++ b/man/pairwise_comparison.Rd @@ -36,7 +36,9 @@ model against which to compare other models.} \code{\link[=compare_two_models]{compare_two_models()}} for more information.} } \value{ -A ggplot2 object with a coloured table of summarised scores +A data.table with pairwise comparisons. In addition, the output is +of class \code{scoringutils_pairwise} and can be visualised using \code{\link[=plot]{plot()}} (which +dispatches \code{\link[=plot.scoringutils_pairwise]{plot.scoringutils_pairwise()}}. } \description{ Compute relative scores between different models making pairwise @@ -70,9 +72,12 @@ scores <- score(example_quantile) pairwise <- pairwise_comparison(scores, by = "target_type") library(ggplot2) -plot_pairwise_comparison(pairwise, type = "mean_scores_ratio") + +plot(pairwise, type = "mean_scores_ratio") + facet_wrap(~target_type) } +\seealso{ +\code{\link[=plot.scoringutils_pairwise]{plot.scoringutils_pairwise()}} +} \author{ Nikos Bosse \email{nikosbosse@gmail.com} diff --git a/man/plot.scoringutils_available_forecasts.Rd b/man/plot.scoringutils_available_forecasts.Rd index f11e0dc5d..26cb3fda8 100644 --- a/man/plot.scoringutils_available_forecasts.Rd +++ b/man/plot.scoringutils_available_forecasts.Rd @@ -48,3 +48,17 @@ plot( ) + facet_wrap("target_type") } +\seealso{ +Other plotting functions: +\code{\link{plot.scoringutils_correlation}()}, +\code{\link{plot.scoringutils_pairwise}()}, +\code{\link{plot_heatmap}()}, +\code{\link{plot_interval_coverage}()}, +\code{\link{plot_pit}()}, +\code{\link{plot_predictions}()}, +\code{\link{plot_quantile_coverage}()}, +\code{\link{plot_ranges}()}, +\code{\link{plot_score_table}()}, +\code{\link{plot_wis}()} +} +\concept{plotting functions} diff --git a/man/plot.scoringutils_correlation.Rd b/man/plot.scoringutils_correlation.Rd new file mode 100644 index 000000000..f56e4eea2 --- /dev/null +++ b/man/plot.scoringutils_correlation.Rd @@ -0,0 +1,42 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot.R +\name{plot.scoringutils_correlation} +\alias{plot.scoringutils_correlation} +\title{Plot Correlation Between Metrics} +\usage{ +\method{plot}{scoringutils_correlation}(x, ...) +} +\arguments{ +\item{x}{An S3 object with correlations between scores as produced by +\code{\link[=correlation]{correlation()}}.} + +\item{...}{additional arguments (not used here)} +} +\value{ +A ggplot2 object showing a coloured matrix of correlations +between metrics +} +\description{ +Plots a heatmap of correlations between different metrics +} +\examples{ +scores <- score(example_quantile) +correlations <- correlation( + summarise_scores(scores) +) +plot(correlations) +} +\seealso{ +Other plotting functions: +\code{\link{plot.scoringutils_available_forecasts}()}, +\code{\link{plot.scoringutils_pairwise}()}, +\code{\link{plot_heatmap}()}, +\code{\link{plot_interval_coverage}()}, +\code{\link{plot_pit}()}, +\code{\link{plot_predictions}()}, +\code{\link{plot_quantile_coverage}()}, +\code{\link{plot_ranges}()}, +\code{\link{plot_score_table}()}, +\code{\link{plot_wis}()} +} +\concept{plotting functions} diff --git a/man/plot.scoringutils_pairwise.Rd b/man/plot.scoringutils_pairwise.Rd new file mode 100644 index 000000000..d4a4d5809 --- /dev/null +++ b/man/plot.scoringutils_pairwise.Rd @@ -0,0 +1,48 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot.R +\name{plot.scoringutils_pairwise} +\alias{plot.scoringutils_pairwise} +\title{Plot Heatmap of Pairwise Comparisons} +\usage{ +\method{plot}{scoringutils_pairwise}(x, type = c("mean_scores_ratio", "pval"), ...) +} +\arguments{ +\item{x}{An S3 object as produced by +\code{\link[=pairwise_comparison]{pairwise_comparison()}}} + +\item{type}{character vector of length one that is either +"mean_scores_ratio" or "pval". This denotes whether to +visualise the ratio or the p-value of the pairwise comparison. +Default is "mean_scores_ratio".} + +\item{...}{additional arguments (not used here)} +} +\value{ +A data.table with pairwise comparisons. In addition, the output is +of class \code{scoringutils_pairwise} and can be visualised using \code{\link[=plot]{plot()}}. +} +\description{ +Creates a heatmap of the ratios or pvalues from a pairwise comparison +between models +} +\examples{ +library(ggplot2) +scores <- score(example_quantile) +pairwise <- pairwise_comparison(scores, by = "target_type") +plot(pairwise, type = "mean_scores_ratio") + + facet_wrap(~target_type) +} +\seealso{ +Other plotting functions: +\code{\link{plot.scoringutils_available_forecasts}()}, +\code{\link{plot.scoringutils_correlation}()}, +\code{\link{plot_heatmap}()}, +\code{\link{plot_interval_coverage}()}, +\code{\link{plot_pit}()}, +\code{\link{plot_predictions}()}, +\code{\link{plot_quantile_coverage}()}, +\code{\link{plot_ranges}()}, +\code{\link{plot_score_table}()}, +\code{\link{plot_wis}()} +} +\concept{plotting functions} diff --git a/man/plot_correlation.Rd b/man/plot_correlation.Rd index 390c90f20..4fd75faf2 100644 --- a/man/plot_correlation.Rd +++ b/man/plot_correlation.Rd @@ -2,25 +2,14 @@ % Please edit documentation in R/plot.R \name{plot_correlation} \alias{plot_correlation} -\title{Plot Correlation Between Metrics} +\title{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Plot Correlation Between Metrics} \usage{ plot_correlation(correlations) } \arguments{ -\item{correlations}{A data.table of correlations between scores as produced -by \code{\link[=correlation]{correlation()}}.} -} -\value{ -A ggplot2 object showing a coloured matrix of correlations -between metrics +\item{correlations}{A data.table with correalations as produced by +\code{\link[=correlation]{correlation()}}} } \description{ -Plots a heatmap of correlations between different metrics -} -\examples{ -scores <- score(example_quantile) -correlations <- correlation( - summarise_scores(scores) -) -plot_correlation(correlations) +Deprecated version of \code{\link[=plot.scoringutils_correlation]{plot.scoringutils_correlation()}} for compatibility. } diff --git a/man/plot_heatmap.Rd b/man/plot_heatmap.Rd index 8b1aac549..4c623e5f0 100644 --- a/man/plot_heatmap.Rd +++ b/man/plot_heatmap.Rd @@ -33,3 +33,17 @@ scores <- summarise_scores(scores, by = c("model", "target_type", "range")) plot_heatmap(scores, x = "target_type", metric = "bias") } +\seealso{ +Other plotting functions: +\code{\link{plot.scoringutils_available_forecasts}()}, +\code{\link{plot.scoringutils_correlation}()}, +\code{\link{plot.scoringutils_pairwise}()}, +\code{\link{plot_interval_coverage}()}, +\code{\link{plot_pit}()}, +\code{\link{plot_predictions}()}, +\code{\link{plot_quantile_coverage}()}, +\code{\link{plot_ranges}()}, +\code{\link{plot_score_table}()}, +\code{\link{plot_wis}()} +} +\concept{plotting functions} diff --git a/man/plot_interval_coverage.Rd b/man/plot_interval_coverage.Rd index 9c7da16fe..9aaa7b679 100644 --- a/man/plot_interval_coverage.Rd +++ b/man/plot_interval_coverage.Rd @@ -26,3 +26,17 @@ scores <- score(example_quantile) scores <- summarise_scores(scores, by = c("model", "range")) plot_interval_coverage(scores) } +\seealso{ +Other plotting functions: +\code{\link{plot.scoringutils_available_forecasts}()}, +\code{\link{plot.scoringutils_correlation}()}, +\code{\link{plot.scoringutils_pairwise}()}, +\code{\link{plot_heatmap}()}, +\code{\link{plot_pit}()}, +\code{\link{plot_predictions}()}, +\code{\link{plot_quantile_coverage}()}, +\code{\link{plot_ranges}()}, +\code{\link{plot_score_table}()}, +\code{\link{plot_wis}()} +} +\concept{plotting functions} diff --git a/man/plot_pairwise_comparison.Rd b/man/plot_pairwise_comparison.Rd index 71b5e77e8..41b5b9579 100644 --- a/man/plot_pairwise_comparison.Rd +++ b/man/plot_pairwise_comparison.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/plot.R \name{plot_pairwise_comparison} \alias{plot_pairwise_comparison} -\title{Plot Heatmap of Pairwise Comparisons} +\title{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Plot Heatmap of Pairwise Comparisons} \usage{ plot_pairwise_comparison( comparison_result, @@ -18,14 +18,30 @@ plot_pairwise_comparison( visualise the ratio or the p-value of the pairwise comparison. Default is "mean_scores_ratio".} } +\value{ +A data.table with pairwise comparisons. In addition, the output is +of class \code{scoringutils_pairwise} and can be visualised using \code{\link[=plot]{plot()}}. +} \description{ -Creates a heatmap of the ratios or pvalues from a pairwise comparison -between models +Deprecated version of \code{\link[=plot.scoringutils_pairwise]{plot.scoringutils_pairwise()}} } \examples{ library(ggplot2) scores <- score(example_quantile) pairwise <- pairwise_comparison(scores, by = "target_type") -plot_pairwise_comparison(pairwise, type = "mean_scores_ratio") + +plot(pairwise, type = "mean_scores_ratio") + facet_wrap(~target_type) } +\seealso{ +Other plotting functions: +\code{\link{plot.scoringutils_available_forecasts}()}, +\code{\link{plot.scoringutils_correlation}()}, +\code{\link{plot_heatmap}()}, +\code{\link{plot_interval_coverage}()}, +\code{\link{plot_pit}()}, +\code{\link{plot_predictions}()}, +\code{\link{plot_quantile_coverage}()}, +\code{\link{plot_ranges}()}, +\code{\link{plot_score_table}()}, +\code{\link{plot_wis}()} +} diff --git a/man/plot_pit.Rd b/man/plot_pit.Rd index d0eceabd3..df4bec54c 100644 --- a/man/plot_pit.Rd +++ b/man/plot_pit.Rd @@ -48,3 +48,17 @@ plot_pit(pit, breaks = seq(0.1, 1, 0.1)) pit <- pit(example_integer,by = "model") plot_pit(pit) } +\seealso{ +Other plotting functions: +\code{\link{plot.scoringutils_available_forecasts}()}, +\code{\link{plot.scoringutils_correlation}()}, +\code{\link{plot.scoringutils_pairwise}()}, +\code{\link{plot_heatmap}()}, +\code{\link{plot_interval_coverage}()}, +\code{\link{plot_predictions}()}, +\code{\link{plot_quantile_coverage}()}, +\code{\link{plot_ranges}()}, +\code{\link{plot_score_table}()}, +\code{\link{plot_wis}()} +} +\concept{plotting functions} diff --git a/man/plot_predictions.Rd b/man/plot_predictions.Rd index 6464262fa..c079a687f 100644 --- a/man/plot_predictions.Rd +++ b/man/plot_predictions.Rd @@ -68,3 +68,17 @@ example_continuous \%>\% facet_wrap(~ location + target_type, scales = "free_y") + aes(fill = model, color = model) } +\seealso{ +Other plotting functions: +\code{\link{plot.scoringutils_available_forecasts}()}, +\code{\link{plot.scoringutils_correlation}()}, +\code{\link{plot.scoringutils_pairwise}()}, +\code{\link{plot_heatmap}()}, +\code{\link{plot_interval_coverage}()}, +\code{\link{plot_pit}()}, +\code{\link{plot_quantile_coverage}()}, +\code{\link{plot_ranges}()}, +\code{\link{plot_score_table}()}, +\code{\link{plot_wis}()} +} +\concept{plotting functions} diff --git a/man/plot_quantile_coverage.Rd b/man/plot_quantile_coverage.Rd index 2e6ef489e..e553ca9a2 100644 --- a/man/plot_quantile_coverage.Rd +++ b/man/plot_quantile_coverage.Rd @@ -25,3 +25,17 @@ scores <- score(example_quantile) scores <- summarise_scores(scores, by = c("model", "quantile")) plot_quantile_coverage(scores) } +\seealso{ +Other plotting functions: +\code{\link{plot.scoringutils_available_forecasts}()}, +\code{\link{plot.scoringutils_correlation}()}, +\code{\link{plot.scoringutils_pairwise}()}, +\code{\link{plot_heatmap}()}, +\code{\link{plot_interval_coverage}()}, +\code{\link{plot_pit}()}, +\code{\link{plot_predictions}()}, +\code{\link{plot_ranges}()}, +\code{\link{plot_score_table}()}, +\code{\link{plot_wis}()} +} +\concept{plotting functions} diff --git a/man/plot_ranges.Rd b/man/plot_ranges.Rd index a4a999ff2..e0acd3739 100644 --- a/man/plot_ranges.Rd +++ b/man/plot_ranges.Rd @@ -41,3 +41,17 @@ plot_ranges(scores, x = "model") + plot_ranges(scores, y = "dispersion", x = "model") + facet_wrap(~target_type) } +\seealso{ +Other plotting functions: +\code{\link{plot.scoringutils_available_forecasts}()}, +\code{\link{plot.scoringutils_correlation}()}, +\code{\link{plot.scoringutils_pairwise}()}, +\code{\link{plot_heatmap}()}, +\code{\link{plot_interval_coverage}()}, +\code{\link{plot_pit}()}, +\code{\link{plot_predictions}()}, +\code{\link{plot_quantile_coverage}()}, +\code{\link{plot_score_table}()}, +\code{\link{plot_wis}()} +} +\concept{plotting functions} diff --git a/man/plot_score_table.Rd b/man/plot_score_table.Rd index 9984e8000..492f5fd10 100644 --- a/man/plot_score_table.Rd +++ b/man/plot_score_table.Rd @@ -45,3 +45,17 @@ plot_score_table(scores, y = c("model", "target_type"), by = "target_type") } +\seealso{ +Other plotting functions: +\code{\link{plot.scoringutils_available_forecasts}()}, +\code{\link{plot.scoringutils_correlation}()}, +\code{\link{plot.scoringutils_pairwise}()}, +\code{\link{plot_heatmap}()}, +\code{\link{plot_interval_coverage}()}, +\code{\link{plot_pit}()}, +\code{\link{plot_predictions}()}, +\code{\link{plot_quantile_coverage}()}, +\code{\link{plot_ranges}()}, +\code{\link{plot_wis}()} +} +\concept{plotting functions} diff --git a/man/plot_wis.Rd b/man/plot_wis.Rd index 982ff1406..984c02126 100644 --- a/man/plot_wis.Rd +++ b/man/plot_wis.Rd @@ -46,3 +46,17 @@ plot_wis(scores, Bracher J, Ray E, Gneiting T, Reich, N (2020) Evaluating epidemic forecasts in an interval format. \url{https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1008618} } +\seealso{ +Other plotting functions: +\code{\link{plot.scoringutils_available_forecasts}()}, +\code{\link{plot.scoringutils_correlation}()}, +\code{\link{plot.scoringutils_pairwise}()}, +\code{\link{plot_heatmap}()}, +\code{\link{plot_interval_coverage}()}, +\code{\link{plot_pit}()}, +\code{\link{plot_predictions}()}, +\code{\link{plot_quantile_coverage}()}, +\code{\link{plot_ranges}()}, +\code{\link{plot_score_table}()} +} +\concept{plotting functions} diff --git a/tests/testthat/test-plot_correlation.R b/tests/testthat/test-plot_correlation.R index 9d6280d6e..8a0e7e67b 100644 --- a/tests/testthat/test-plot_correlation.R +++ b/tests/testthat/test-plot_correlation.R @@ -1,6 +1,6 @@ -test_that("plot_correlation() works as expected", { +test_that("plot works as expected for correlation", { correlations <- correlation(summarise_scores(scores)) - p <- plot_correlation(correlations) + p <- plot(correlations) expect_s3_class(p, "ggplot") skip_on_cran() vdiffr::expect_doppelganger("plot__correlation", p) diff --git a/tests/testthat/test-plot_pairwise_comparison.R b/tests/testthat/test-plot_pairwise_comparison.R index 4cd477e90..c4839a264 100644 --- a/tests/testthat/test-plot_pairwise_comparison.R +++ b/tests/testthat/test-plot_pairwise_comparison.R @@ -2,16 +2,16 @@ pairwise <- suppressMessages( pairwise_comparison(scores, by = "target_type") ) -test_that("plot_pairwise_comparison() works as expected", { - p <- plot_pairwise_comparison(pairwise) + +test_that("plot() for pairwise comparisons works as expected", { + p <- plot(pairwise) + ggplot2::facet_wrap(~target_type) expect_s3_class(p, "ggplot") skip_on_cran() vdiffr::expect_doppelganger("plot_pairwise_comparison", p) }) -test_that("plot_pairwise_comparison() works when showing p values", { - p <- plot_pairwise_comparison(pairwise, type = "pval") + +test_that("plot() for pairwise comparisons works when showing p values", { + p <- plot(pairwise, type = "pval") + ggplot2::facet_wrap(~target_type) expect_s3_class(p, "ggplot") skip_on_cran() diff --git a/vignettes/scoringutils.Rmd b/vignettes/scoringutils.Rmd index b4dd0bf16..80c2d1321 100644 --- a/vignettes/scoringutils.Rmd +++ b/vignettes/scoringutils.Rmd @@ -351,7 +351,7 @@ If using the `pairwise_comparison()` function, we can also visualise pairwise co example_quantile %>% score() %>% pairwise_comparison(by = c("model", "target_type")) %>% - plot_pairwise_comparison() + + plot() + facet_wrap(~ target_type) ``` @@ -376,7 +376,7 @@ example_quantile %>% score() %>% summarise_scores() %>% correlation() %>% - plot_correlation() + plot() ``` ### Scores by interval ranges