Skip to content

Commit

Permalink
Merge pull request #113 from cchrisgong/master
Browse files Browse the repository at this point in the history
revert PR 111
  • Loading branch information
cchrisgong authored Sep 23, 2024
2 parents a9ddfb6 + 2d6b184 commit 517255a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '30175840'
ValidationKey: '30203379'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -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.151.0
date-released: '2024-09-18'
version: 0.151.1
date-released: '2024-09-23'
abstract: Package contains generic functions to produce comparison plots of multi-model
runs.
authors:
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: mip
Title: Comparison of multi-model runs
Version: 0.151.0
Date: 2024-09-18
Version: 0.151.1
Date: 2024-09-23
Authors@R: c(
person("David", "Klein", , "[email protected]", role = c("aut", "cre")),
person("Jan Philipp", "Dietrich", , "[email protected]", role = "aut"),
Expand Down
52 changes: 23 additions & 29 deletions R/mipArea.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,40 +82,34 @@ mipArea <- function(x, stack_priority = c("variable", "region"), total = TRUE, s
###
### Find out which variables to stack and which to put to facet_grid
###
if ("identifier" %in% names(x)) {
# if the identifier is specified externally, us that + region as facet and stack variables
facets <- c("identifier", "region")
if (!is.null(hist)) x <- rbind(x, hist)
dimToStack <- "variable"
} else {
# Identify stacking and facet_grid based on data
# count levels of the given columns
nLevels <- vapply(subset(x, select = c("variable", "region", "scenario", "model")), nlevels, integer(1))

# Find first dimension in stack_priority that has more than one element.
# Initialize dimToStack (this applies if if all dimensions have only one element)
dimToStack <- stack_priority[1]
for (s in stack_priority) {
if (nLevels[s] > 1) {
dimToStack <- s
break
}

# count levels of the given columns
nLevels <- vapply(subset(x, select = c("variable", "region", "scenario", "model")), nlevels, integer(1))

# Find first dimension in stack_priority that has more than one element.
# Initialize dimToStack (this applies if if all dimensions have only one element)
dimToStack <- stack_priority[1]
for (s in stack_priority) {
if (nLevels[s] > 1) {
dimToStack <- s
break
}
}

# find and sort dimension with more than one element, exclude dimToStack
# sort: to be able to build the interaction with the smallest number of resulting combinations (further down)
facets <- sort(nLevels[nLevels > 1])
facets <- setdiff(names(facets), dimToStack)
# find and sort dimension with more than one element, exclude dimToStack
# sort: to be able to build the interaction with the smallest number of resulting combinations (further down)
facets <- sort(nLevels[nLevels > 1])
facets <- setdiff(names(facets), dimToStack)

# Combine data and historical data into one object
if (!is.null(hist)) x <- rbind(x, hist)
# Combine data and historical data into one object
if (!is.null(hist)) x <- rbind(x, hist)

# if there are three facet dimensions that have more than one element combine the two
# smallest ones into the first one to be able to create a 2-D facet_grid later on
if (length(facets) == 3) {
x[, facets[1]] <- paste(x[[facets[2]]], x[[facets[1]]])
}
# if there are three facet dimensions that have more than one element combine the two
# smallest ones into the first one to be able to create a 2-D facet_grid later on
if (length(facets) == 3) {
x[, facets[1]] <- paste(x[[facets[2]]], x[[facets[1]]])
}

# if not provided by user calculate total by summing over dimToStack
if (isTRUE(total)) {
dimToGroup <- setdiff(c("model", "scenario", "region", "variable", "unit", "period"), dimToStack)
Expand Down
1 change: 0 additions & 1 deletion R/showAreaAndBarPlots.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ showAreaAndBarPlots <- function(
.data$region == .env$mainReg,
.data$variable == .env$tot) %>%
droplevels()
dMainTot$scenario <- dMainTot$identifier
p1 <- p1 +
geom_line(
data = dMainTot,
Expand Down
6 changes: 3 additions & 3 deletions 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.151.0**
R package **mip**, version **0.151.1**

[![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,7 @@ In case of questions / problems please contact David Klein <[email protected]

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

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 <https://doi.org/10.5281/zenodo.1158586>, R package version 0.151.0, <https://github.com/pik-piam/mip>.
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 <https://doi.org/10.5281/zenodo.1158586>, R package version 0.151.1, <https://github.com/pik-piam/mip>.

A BibTeX entry for LaTeX users is

Expand All @@ -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.151.0},
note = {R package version 0.151.1},
url = {https://github.com/pik-piam/mip},
doi = {10.5281/zenodo.1158586},
}
Expand Down

0 comments on commit 517255a

Please sign in to comment.