diff --git a/.buildlibrary b/.buildlibrary index 25715ef..15496ea 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '27084132' +ValidationKey: '27296190' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/.github/workflows/lucode2-check.yaml b/.github/workflows/lucode2-check.yaml index 96a045b..7acf601 100644 --- a/.github/workflows/lucode2-check.yaml +++ b/.github/workflows/lucode2-check.yaml @@ -28,6 +28,7 @@ jobs: curl -OLs https://eddelbuettel.github.io/r-ci/run.sh chmod 0755 run.sh ./run.sh bootstrap + rm -f bspm_*.tar.gz - name: Enable r-universe repo, modify bspm integration run: | @@ -48,6 +49,7 @@ jobs: pkgs <- c(bspm::install_sys(pkgs[!pkgs %%in%% noBinaryInstallRPackages]), pkgs[pkgs %%in%% noBinaryInstallRPackages]) } + type <- "source" }) trace(utils::install.packages, expr, print = FALSE) }) @@ -67,9 +69,9 @@ jobs: uses: pat-s/always-upload-cache@v3 with: path: /usr/local/lib/R/ - key: 2-${{ runner.os }}-usr-local-lib-R-${{ hashFiles('DESCRIPTION') }} + key: 3-${{ runner.os }}-usr-local-lib-R-${{ hashFiles('DESCRIPTION') }} restore-keys: | - 2-${{ runner.os }}-usr-local-lib-R- + 3-${{ runner.os }}-usr-local-lib-R- - name: Restore R library permissions run: | diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9dfc157..d9409d2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,7 +15,7 @@ repos: - id: mixed-line-ending - repo: https://github.com/lorenzwalthert/precommit - rev: v0.3.2.9003 + rev: v0.3.2.9007 hooks: - id: parsable-R - id: deps-in-desc diff --git a/.zenodo.json b/.zenodo.json index 84b5271..f04fcf0 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -1,6 +1,6 @@ { "title": "mip: Comparison of multi-model runs", - "version": "0.140.1", + "version": "0.141.0", "description": "

Package contains generic functions to produce comparison\n plots of multi-model runs.<\/p>", "creators": [ { @@ -23,6 +23,9 @@ }, { "name": "Führlich, Pascal" + }, + { + "name": "Richters, Oliver" } ] } diff --git a/DESCRIPTION b/DESCRIPTION index 22d57e5..3ec8795 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: mip Title: Comparison of multi-model runs -Version: 0.140.1 -Date: 2022-12-06 +Version: 0.141.0 +Date: 2023-01-02 Authors@R: c( person("David", "Klein", , "dklein@pik-potsdam.de", role = c("aut", "cre")), person("Jan Philipp", "Dietrich", , "dietrich@pik-potsdam.de", role = "aut"), @@ -10,7 +10,8 @@ Authors@R: c( person("Florian", "Humpenoeder", , "humpenoeder@pik-potsdam.de", role = "aut"), person("Miodrag", "Stevanovic", , "miodrag@pik-potsdam.de", role = "aut"), person("Stephen", "Wirth", , "wirth@pik-potsdam.de", role = "aut"), - person("Pascal", "Führlich", , "pascal.fuehrlich@pik-potsdam.de", role = "aut") + person("Pascal", "Führlich", , "pascal.fuehrlich@pik-potsdam.de", role = "aut"), + person("Oliver", "Richters", role = "aut") ) Description: Package contains generic functions to produce comparison plots of multi-model runs. @@ -46,4 +47,4 @@ VignetteBuilder: knitr Encoding: UTF-8 LazyData: yes -RoxygenNote: 7.2.2 +RoxygenNote: 7.2.3 diff --git a/R/mipBarYearData.R b/R/mipBarYearData.R index b69b941..97fa6f2 100644 --- a/R/mipBarYearData.R +++ b/R/mipBarYearData.R @@ -1,12 +1,12 @@ #' @title mipBarYearData -#' @description Function for plotting (bar-plot) MAgPIE objects and compare different scenarios, -#' on the x-axis for some time steps one bar for each scenario is generated +#' @description Function for plotting (bar-plot) MAgPIE objects and compare different scenarios +#' or models, on the x-axis for some time steps one bar for each scenario/model is generated #' #' #' @param x Data to plot. Allowed data formats: magpie or quitte #' @param ylab y-axis text #' @param xlab x-axis text -#' @param title title appering at the top of the plot +#' @param title title appearing at the top of the plot #' @param colour Dimension to be colored, default: "Scenario" #' @param scenario_markers Use markers to conserve space with long scenario #' names. Symbols are either picked automatically (default), or can be @@ -15,7 +15,7 @@ #' and 20, or a ggplot2 shape name #' (see \code{vignette("ggplot2-specs")}). Set to \code{FALSE} to not #' use markers. -#' @author Lavinia Baumstark +#' @author Lavinia Baumstark, Oliver Richters #' @section Example Plot: #' \if{html}{\figure{mipBarYearData.png}{example plot}} #' \if{html}{\figure{mipBarYearData_oneRegi.png}{example plot}} @@ -40,16 +40,22 @@ mipBarYearData <- function(x, colour = NULL, ylab = NULL, xlab = NULL, title = NULL, scenario_markers = TRUE) { #nolint scenarioMarkers <- scenario_markers - x <- as.quitte(x) + x <- droplevels(as.quitte(x)) - if (length(unique(x$model)) > 1) { - stop("this plot can only deal with data that have only one model") - } + x$identifier <- as.factor(paste0(if (nlevels(x$model) > 1) x$model, + if (nlevels(x$model) > 1 && nlevels(x$scenario) > 1) " ", + if (nlevels(x$scenario) > 1 || nlevels(x$model) == 1) x$scenario + )) if (!is.integer(x$period)) { stop("this plot can only deal with data that have integer periods") } + if (nrow(x) == 0) { + warning("Quitte object is empty.") + return() + } + # calculate y-axis label x$variable <- shorten_legend(x$variable, identical_only = TRUE) @@ -61,19 +67,18 @@ mipBarYearData <- function(x, colour = NULL, ylab = NULL, xlab = NULL, title = N } # add dummy-dimension for space between the time-steps - xpos <- crossing(period = unique(x$period), - scenario = factor(c(levels(x$scenario), "\x13"))) %>% - order.levels(scenario = c(levels(x$scenario), "\x13")) %>% - arrange(!!sym("period"), !!sym("scenario")) %>% - mutate(xpos = 1:n()) %>% - filter("\x13" != !!sym("scenario")) %>% - droplevels() + xpos <- crossing(period = unique(x$period), + identifier = factor(c(levels(x$identifier), "\x13"))) %>% + order.levels(identifier = c(levels(x$identifier), "\x13")) %>% + arrange(!!sym("period"), !!sym("identifier")) %>% + mutate(xpos = 1:n()) %>% + filter("\x13" != !!sym("identifier")) %>% + droplevels() x <- x %>% inner_join( xpos, - - c("scenario", "period") + c("identifier", "period") ) if (scenarioMarkers) { @@ -93,8 +98,8 @@ mipBarYearData <- function(x, colour = NULL, ylab = NULL, xlab = NULL, title = N } if (scenarioMarkers) { - scenarioMarkers <- stats::setNames((1:20)[seq_along(unique(x$scenario))], - levels(x$scenario)) + scenarioMarkers <- stats::setNames((1:20)[seq_along(unique(x$identifier))], + levels(x$identifier)) } # calculate positions of period labels @@ -126,7 +131,7 @@ mipBarYearData <- function(x, colour = NULL, ylab = NULL, xlab = NULL, title = N labels = xpos$period) + geom_point(data = yMarker, mapping = aes(x = !!sym("xpos"), y = !!sym("y"), - shape = !!sym("scenario")), + shape = !!sym("identifier")), size = 1.5) + scale_shape_manual(values = scenarioMarkers, name = NULL) + theme(legend.box = "vertical") @@ -134,7 +139,7 @@ mipBarYearData <- function(x, colour = NULL, ylab = NULL, xlab = NULL, title = N p <- p + scale_x_continuous(breaks = xpos$xpos, labels = xpos %>% - unite(!!sym("label"), !!sym("scenario"), + unite(!!sym("label"), !!sym("identifier"), !!sym("period"), sep = " ") %>% getElement("label")) + theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) diff --git a/README.md b/README.md index f521398..4b567f0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Comparison of multi-model runs -R package **mip**, version **0.140.1** +R package **mip**, version **0.141.0** [![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/ui#builds) @@ -47,16 +47,16 @@ In case of questions / problems please contact David Klein . +Klein D, Dietrich J, Baumstark L, Humpenoeder F, Stevanovic M, Wirth S, Führlich P, Richters O (2023). _mip: Comparison of multi-model runs_. doi: 10.5281/zenodo.1158586 (URL: https://doi.org/10.5281/zenodo.1158586), R package version 0.141.0, . A BibTeX entry for LaTeX users is ```latex @Manual{, 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}, - year = {2022}, - note = {R package version 0.140.1}, + 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}, + year = {2023}, + note = {R package version 0.141.0}, doi = {10.5281/zenodo.1158586}, url = {https://github.com/pik-piam/mip}, } diff --git a/man/mipBarYearData.Rd b/man/mipBarYearData.Rd index cbe7028..c376d2f 100644 --- a/man/mipBarYearData.Rd +++ b/man/mipBarYearData.Rd @@ -22,7 +22,7 @@ mipBarYearData( \item{xlab}{x-axis text} -\item{title}{title appering at the top of the plot} +\item{title}{title appearing at the top of the plot} \item{scenario_markers}{Use markers to conserve space with long scenario names. Symbols are either picked automatically (default), or can be @@ -33,8 +33,8 @@ and 20, or a ggplot2 shape name use markers.} } \description{ -Function for plotting (bar-plot) MAgPIE objects and compare different scenarios, -on the x-axis for some time steps one bar for each scenario is generated +Function for plotting (bar-plot) MAgPIE objects and compare different scenarios +or models, on the x-axis for some time steps one bar for each scenario/model is generated } \section{Example Plot}{ @@ -51,5 +51,5 @@ plotCompBarYearData(EnInv, ylab = "Energy Investments|Elec (billion US$2005/yr)" } \author{ -Lavinia Baumstark +Lavinia Baumstark, Oliver Richters }