Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pik-piam/mip into adapt-to-pCap-b…
Browse files Browse the repository at this point in the history
…uildings
  • Loading branch information
ricardarosemann committed Feb 13, 2024
2 parents 84687be + e3cc350 commit fb65f18
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '291045059760'
ValidationKey: '29284320'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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.147.2.9001
version: 0.148.2
date-released: '2024-02-07'
abstract: Package contains generic functions to produce comparison plots of multi-model
runs.
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: mip
Title: Comparison of multi-model runs
Version: 0.147.2.9001
Version: 0.148.2
Date: 2024-02-07
Authors@R: c(
person("David", "Klein", , "[email protected]", role = c("aut", "cre")),
Expand Down
9 changes: 6 additions & 3 deletions R/showMultiLinePlots.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' \code{variable}. The plots arranged and shown.
#'
#' @param vars A character vector. The variables to be plotted.
#' @param nrowNum An integer value. Number of rows of the panel figures
#' @inheritParams showLinePlots
#' @return \code{NULL} is returned invisible.
#' @section Example Plots:
Expand All @@ -27,6 +28,7 @@
#' @importFrom ggplot2 ylim
showMultiLinePlots <- function(
data, vars, scales = "free_y",
nrowNum = 1,
mainReg = getOption("mip.mainReg")
) {

Expand Down Expand Up @@ -62,22 +64,23 @@ showMultiLinePlots <- function(
}

label <- paste0("(", paste0(levels(d$unit), collapse = ","), ")")

p1 <- dMainScen %>%
ggplot(aes(.data$period, .data$value)) +
geom_line(aes(linetype = .data$scenario)) +
geom_point(data = dMainHist, aes(shape = .data$model)) +
geom_line(data = dMainHist, aes(group = paste0(.data$model, .data$region)), alpha = 0.5) +
facet_wrap(vars(.data$variable), scales = scales) +
facet_wrap(vars(.data$variable), scales = scales, nrow = nrowNum) +
theme_minimal() +
expand_limits(y = 0) +
ylab(label)

p2 <- dRegiScen %>%
ggplot(aes(.data$period, .data$value, color = .data$region)) +
geom_line(aes(linetype = .data$scenario)) +
geom_point(data = dRegiHist, aes(shape = .data$model)) +
geom_line(data = dRegiHist, aes(group = paste0(.data$model, .data$region)), alpha = 0.5) +
facet_wrap(vars(.data$variable), scales = scales) +
facet_wrap(vars(.data$variable), scales = scales, nrow = nrowNum) +
theme_minimal() +
scale_color_manual(values = plotstyle(regions)) +
expand_limits(y = 0) +
Expand Down
54 changes: 34 additions & 20 deletions R/showMultiLinePlotsByVariable.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#' @param showHistorical A single logical value. Should historical data be
#' shown? It is not recommended to set this to \code{TRUE} as the resulting
#' plot we probably be quite confusing.
#' @param showGlobal A single logical value. Should global data be
#' shown? Default is false to save space in pdf
#' @param nrowNum An integer value. Number of rows of the panel figures
#' @param histRefModel A named character vector identifying the unique model to
#' be chosen for historical data. Use \code{options(mip.histRefModel=<value>)}
#' to set globally.
Expand Down Expand Up @@ -42,6 +45,8 @@
showMultiLinePlotsByVariable <- function(
data, vars, xVar, scales = "free_y",
showHistorical = FALSE,
showGlobal = FALSE,
nrowNum = 1,
mainReg = getOption("mip.mainReg"),
histRefModel = getOption("mip.histRefModel"),
yearsByVariable = getOption("mip.yearsBarPlot")
Expand Down Expand Up @@ -92,39 +97,46 @@ showMultiLinePlotsByVariable <- function(

label <- paste0("(", paste0(levels(d$unit), collapse = ","), ")")
xLabel <- paste0(xVar, " (", paste0(levels(d$unit.x), collapse = ","), ")")

p1 <- dMainScen %>%
ggplot(aes(.data$value.x, .data$value)) +
geom_line(aes(linetype = .data$scenario)) +
facet_wrap(vars(.data$variable), scales = scales) +
theme_minimal() +
expand_limits(y = 0) +
ylab(label) + xlab(xLabel)

if (showGlobal) {
p1 <- dMainScen %>%
ggplot(aes(.data$value.x, .data$value)) +
geom_line(aes(linetype = .data$scenario)) +
facet_wrap(vars(.data$variable), scales = scales, nrow = nrowNum) +
theme_minimal() +
expand_limits(y = 0) +
ylab(label) + xlab(xLabel)
}
p2 <- dRegiScen %>%
ggplot(aes(.data$value.x, .data$value, color = .data$region)) +
geom_line(aes(linetype = .data$scenario)) +
facet_wrap(vars(.data$variable), scales = scales) +
facet_wrap(vars(.data$variable), scales = scales, nrow = nrowNum) +
theme_minimal() +
scale_color_manual(values = plotstyle(regions)) +
expand_limits(y = 0) +
ylab(label) + xlab(xLabel)

if (showHistorical) {
stopifnot(xVar %in% names(histRefModel))
p1 <- p1 +
geom_point(data = dMainHist, aes(shape = .data$model)) +
geom_line(data = dMainHist, aes(group = paste0(.data$model, .data$region)), alpha = 0.5)
if (showGlobal) {
p1 <- p1 +
geom_point(data = dMainHist, aes(shape = .data$model)) +
geom_line(data = dMainHist, aes(group = paste0(.data$model, .data$region)), alpha = 0.5)
}
p2 <- p2 +
geom_point(data = dRegiHist, aes(shape = .data$model)) +
geom_line(data = dRegiHist, aes(group = paste0(.data$model, .data$region)), alpha = 0.5)
}
# Add markers for certain years.
if (length(yearsByVariable) > 0) {
p1 <- p1 +
geom_point(
data = dMainScen %>%
filter(.data$period %in% .env$yearsByVariable) %>%
mutate(year = factor(.data$period)),
mapping = aes(.data$value.x, .data$value, shape = .data$year))
if (showGlobal) {
p1 <- p1 +
geom_point(
data = dMainScen %>%
filter(.data$period %in% .env$yearsByVariable) %>%
mutate(year = factor(.data$period)),
mapping = aes(.data$value.x, .data$value, shape = .data$year))
}
p2 <- p2 +
geom_point(
data = dRegiScen %>%
Expand All @@ -134,8 +146,10 @@ showMultiLinePlotsByVariable <- function(
}

# Show plots.
print(p1)
cat("\n\n")
if (showGlobal) {
print(p1)
cat("\n\n")
}
print(p2)
cat("\n\n")

Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Comparison of multi-model runs

R package **mip**, version **0.147.2.9001**
R package **mip**, version **0.148.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)

Expand Down Expand Up @@ -47,7 +47,11 @@ In case of questions / problems please contact David Klein <[email protected]

To cite package **mip** in publications use:

<<<<<<< HEAD
Klein D, Dietrich J, Baumstark L, Humpenoeder F, Stevanovic M, Wirth S, Führlich P, Richters O (2024). _mip: Comparison of multi-model runs_. doi:10.5281/zenodo.1158586 <https://doi.org/10.5281/zenodo.1158586>, R package version 0.147.2.9001, <https://github.com/pik-piam/mip>.
=======
Klein D, Dietrich J, Baumstark L, Humpenoeder F, Stevanovic M, Wirth S, Führlich P, Richters O (2024). _mip: Comparison of multi-model runs_. doi:10.5281/zenodo.1158586 <https://doi.org/10.5281/zenodo.1158586>, R package version 0.148.2, <https://github.com/pik-piam/mip>.
>>>>>>> e3cc350d0c48447549e69c934dcb218dd35374d8
A BibTeX entry for LaTeX users is

Expand All @@ -56,7 +60,11 @@ 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},
year = {2024},
<<<<<<< HEAD
note = {R package version 0.147.2.9001},
=======
note = {R package version 0.148.2},
>>>>>>> e3cc350d0c48447549e69c934dcb218dd35374d8
doi = {10.5281/zenodo.1158586},
url = {https://github.com/pik-piam/mip},
}
Expand Down
3 changes: 3 additions & 0 deletions man/showMultiLinePlots.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions man/showMultiLinePlotsByVariable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fb65f18

Please sign in to comment.