diff --git a/.buildlibrary b/.buildlibrary index 22faa1a..e7ccef3 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '29693265' +ValidationKey: '29744512' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/CITATION.cff b/CITATION.cff index 9715967..9d8d7b9 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -2,8 +2,8 @@ cff-version: 1.2.0 message: If you use this software, please cite it using the metadata from this file. type: software title: 'mip: Comparison of multi-model runs' -version: 0.149.1 -date-released: '2024-07-11' +version: 0.149.2 +date-released: '2024-08-01' abstract: Package contains generic functions to produce comparison plots of multi-model runs. authors: diff --git a/DESCRIPTION b/DESCRIPTION index 067cec2..522af62 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: mip Title: Comparison of multi-model runs -Version: 0.149.1 -Date: 2024-07-11 +Version: 0.149.2 +Date: 2024-08-01 Authors@R: c( person("David", "Klein", , "dklein@pik-potsdam.de", role = c("aut", "cre")), person("Jan Philipp", "Dietrich", , "dietrich@pik-potsdam.de", role = "aut"), diff --git a/R/showLinePlots.R b/R/showLinePlots.R index 61f361d..307b7e0 100644 --- a/R/showLinePlots.R +++ b/R/showLinePlots.R @@ -8,9 +8,14 @@ #' #' @param vars A character vector. Usually just a single string. The variables #' to be plotted. If \code{NULL} all rows from \code{data} are plotted. +#' @param histVars A character vector. Usually just a single string. The historical variables +#' to be plotted. If \code{NULL}, it is set to \code{vars}. #' @param scales A single string. choose either \code{"free_y"} or \code{"fixed"}. #' @param color.dim.name name for the color-dimension used in the legend -#' @param color.dim.manual optional vector with manual colors replacing default colors of color.dim, default is \code{NULL}. +#' @param histModelsExclude A character vector with historical models to exclude. +#' Set to \code{NULL} (default) for all available data. +#' @param color.dim.manual optional vector with manual colors replacing default +#' colors of color.dim, default is \code{NULL}. #' @inheritParams showAreaAndBarPlots #' @return \code{NULL} is returned invisible. #' @section Example Plots: @@ -27,8 +32,14 @@ #' @importFrom gridExtra arrangeGrob showLinePlots <- function( - data, vars = NULL, scales = "free_y", color.dim.name = NULL, - mainReg = getOption("mip.mainReg"), color.dim.manual = NULL + data, + vars = NULL, + histVars = NULL, + scales = "free_y", + color.dim.name = NULL, + mainReg = getOption("mip.mainReg"), + color.dim.manual = NULL, + histModelsExclude = NULL ) { data <- as.quitte(data) %>% @@ -36,16 +47,23 @@ showLinePlots <- function( # Validate function arguments. stopifnot(is.character(vars) || is.null(vars)) + stopifnot(is.character(histVars) || is.null(histVars)) + stopifnot(is.character(histModelsExclude) || is.null(histModelsExclude)) stopifnot(is.character(scales) && length(scales) == 1) checkGlobalOptionsProvided("mainReg") stopifnot(is.character(mainReg) && length(mainReg) == 1) + if (is.null(histVars)) { + histVars <- vars + } + if (!is.null(vars)) { + v <- unique(c(vars, histVars)) d <- data %>% - filter(.data$variable %in% .env$vars) %>% + filter(.data$variable %in% .env$v) %>% droplevels() unitlabel <- ifelse(length(levels(d$unit)) == 0, "", paste0(" (", paste0(levels(d$unit), collapse = ","), ")")) - label <- paste0(paste0(vars, collapse = ","), unitlabel) + label <- paste0(paste0(v, collapse = ","), unitlabel) } else { d <- data %>% droplevels() @@ -53,17 +71,22 @@ showLinePlots <- function( label <- paste0(paste0(levels(d$variable), collapse = ","), unitlabel) } + if (!is.null(histModelsExclude)) { + d <- d %>% + filter(.data$scenario != "historical" | !.data$model %in% .env$histModelsExclude) + } + dMainScen <- d %>% - filter(.data$region == .env$mainReg, .data$scenario != "historical") %>% + filter(.data$region == .env$mainReg, .data$scenario != "historical", .data$variable %in% .env$vars) %>% droplevels() dMainHist <- d %>% - filter(.data$region == .env$mainReg, .data$scenario == "historical") %>% + filter(.data$region == .env$mainReg, .data$scenario == "historical", .data$variable %in% .env$histVars) %>% droplevels() dRegiScen <- d %>% - filter(.data$region != .env$mainReg, .data$scenario != "historical") %>% + filter(.data$region != .env$mainReg, .data$scenario != "historical", .data$variable %in% .env$vars) %>% droplevels() dRegiHist <- d %>% - filter(.data$region != .env$mainReg, .data$scenario == "historical") %>% + filter(.data$region != .env$mainReg, .data$scenario == "historical", .data$variable %in% .env$histVars) %>% droplevels() # make sure all plots use the same colors for historical models diff --git a/README.md b/README.md index 240a4b9..1adc79f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Comparison of multi-model runs -R package **mip**, version **0.149.1** +R package **mip**, version **0.149.2** [![CRAN status](https://www.r-pkg.org/badges/version/mip)](https://cran.r-project.org/package=mip) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1158586.svg)](https://doi.org/10.5281/zenodo.1158586) [![R build status](https://github.com/pik-piam/mip/workflows/check/badge.svg)](https://github.com/pik-piam/mip/actions) [![codecov](https://codecov.io/gh/pik-piam/mip/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mip) [![r-universe](https://pik-piam.r-universe.dev/badges/mip)](https://pik-piam.r-universe.dev/builds) @@ -47,7 +47,7 @@ In case of questions / problems please contact David Klein , R package version 0.149.1, . +Klein D, Dietrich J, Baumstark L, Humpenoeder F, Stevanovic M, Wirth S, Führlich P, Richters O, Rüter T (2024). _mip: Comparison of multi-model runs_. doi:10.5281/zenodo.1158586 , R package version 0.149.2, . A BibTeX entry for LaTeX users is @@ -56,7 +56,7 @@ A BibTeX entry for LaTeX users is title = {mip: Comparison of multi-model runs}, author = {David Klein and Jan Philipp Dietrich and Lavinia Baumstark and Florian Humpenoeder and Miodrag Stevanovic and Stephen Wirth and Pascal Führlich and Oliver Richters and Tonn Rüter}, year = {2024}, - note = {R package version 0.149.1}, + note = {R package version 0.149.2}, url = {https://github.com/pik-piam/mip}, doi = {10.5281/zenodo.1158586}, } diff --git a/man/showLinePlots.Rd b/man/showLinePlots.Rd index 1aac35b..62b3f3f 100644 --- a/man/showLinePlots.Rd +++ b/man/showLinePlots.Rd @@ -7,10 +7,12 @@ showLinePlots( data, vars = NULL, + histVars = NULL, scales = "free_y", color.dim.name = NULL, mainReg = getOption("mip.mainReg"), - color.dim.manual = NULL + color.dim.manual = NULL, + histModelsExclude = NULL ) } \arguments{ @@ -20,6 +22,9 @@ quitte object.} \item{vars}{A character vector. Usually just a single string. The variables to be plotted. If \code{NULL} all rows from \code{data} are plotted.} +\item{histVars}{A character vector. Usually just a single string. The historical variables +to be plotted. If \code{NULL}, it is set to \code{vars}.} + \item{scales}{A single string. choose either \code{"free_y"} or \code{"fixed"}.} \item{color.dim.name}{name for the color-dimension used in the legend} @@ -27,7 +32,11 @@ to be plotted. If \code{NULL} all rows from \code{data} are plotted.} \item{mainReg}{A single string. The plots for this region are shown enlarged. Use \code{options(mip.mainReg=)} to set globally.} -\item{color.dim.manual}{optional vector with manual colors replacing default colors of color.dim, default is \code{NULL}.} +\item{color.dim.manual}{optional vector with manual colors replacing default +colors of color.dim, default is \code{NULL}.} + +\item{histModelsExclude}{A character vector with historical models to exclude. +Set to \code{NULL} (default) for all available data.} } \value{ \code{NULL} is returned invisible.