diff --git a/.buildlibrary b/.buildlibrary index 407f8fb..a024575 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,7 +1,8 @@ -ValidationKey: '71333600' +ValidationKey: '71501411' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' AcceptedNotes: unable to verify current time allowLinterWarnings: yes +enforceVersionUpdate: no diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 870f216..46f518a 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -49,6 +49,11 @@ jobs: shell: Rscript {0} run: lucode2:::validkey(stopIfInvalid = TRUE) + - name: Verify that lucode2::buildLibrary was successful + if: github.event_name == 'pull_request' + shell: Rscript {0} + run: lucode2:::isVersionUpdated() + - name: Checks shell: Rscript {0} run: | diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2f13466..243f46a 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.9025 + rev: v0.4.0 hooks: - id: parsable-R - id: deps-in-desc diff --git a/CITATION.cff b/CITATION.cff index 6ac7f08..2b1d6fc 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: 'luplot: Landuse Plot Library' -version: 3.61.0 -date-released: '2024-02-07' +version: 3.61.1 +date-released: '2024-03-19' abstract: Some useful functions to plot data such as a map plot function for MAgPIE objects. authors: @@ -37,6 +37,9 @@ authors: - family-names: Wang given-names: Xiaoxi email: wang@pik-potsdam.de +- family-names: Chen + given-names: David + email: davidch@pik-potsdam.de license: LGPL-3.0 repository-code: https://github.com/pik-piam/luplot diff --git a/DESCRIPTION b/DESCRIPTION index 39da3da..69f45cc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: luplot Title: Landuse Plot Library -Version: 3.61.0 -Date: 2024-02-07 +Version: 3.61.1 +Date: 2024-03-19 Authors@R: c( person("Benjamin Leon", "Bodirsky", , "bodirsky@pik-potsdam.de", role = c("aut", "cre")), person("Jan Philipp", "Dietrich", , "dietrich@pik-potsdam.de", role = "aut"), @@ -13,7 +13,8 @@ Authors@R: c( person("Lavinia", "Baumstark", , "baumstark@pik-potsdam.de", role = "aut"), person("David", "Klein", , "klein@pik-potsdam.de", role = "aut"), person("Susanne", "Rolinski", , "rolinski@pik-potsdam.de", role = "aut"), - person("Xiaoxi", "Wang", , "wang@pik-potsdam.de", role = "aut") + person("Xiaoxi", "Wang", , "wang@pik-potsdam.de", role = "aut"), + person("David", "Chen", , "davidch@pik-potsdam.de", role = "aut") ) Maintainer: Benjamin Bodirsky Description: Some useful functions to plot data such as a map plot @@ -40,7 +41,8 @@ Imports: rworldmap, sp, xml2, - gridExtra + gridExtra, + mrcommons Suggests: covr Encoding: UTF-8 diff --git a/NAMESPACE b/NAMESPACE index e09b384..a2b2b2e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -161,6 +161,7 @@ importFrom(magclass,where) importFrom(magpiesets,findset) importFrom(magpiesets,reportingnames) importFrom(mip,plotstyle) +importFrom(mrcommons,toolGetMappingCoord2Country) importFrom(quitte,as.quitte) importFrom(reshape2,melt) importFrom(rworldmap,addMapLegendBoxes) diff --git a/R/plotmap2.R b/R/plotmap2.R index 06d05bc..74bff7f 100644 --- a/R/plotmap2.R +++ b/R/plotmap2.R @@ -43,7 +43,7 @@ #' @param facet_style style of facets, default or paper #' @param plot_height plot height in cm #' @param plot_width plot width in cm -#' @author Florian Humpenoeder +#' @author Florian Humpenoeder, David M Chen #' @seealso \code{\link{plotmap}} #' @examples #' # plotmap2(data) @@ -52,6 +52,7 @@ #' @importFrom ggplot2 ggplot aes_ geom_polygon scale_fill_manual waiver geom_raster scale_fill_gradient2 scale_fill_gradient theme coord_cartesian ggtitle element_rect element_line scale_x_continuous scale_y_continuous geom_path element_text element_blank guides guide_colorbar ggsave unit #' @importFrom grDevices colorRampPalette #' @importFrom utils head tail +#' @importFrom mrcommons toolGetMappingCoord2Country plotmap2 <- function(data, file = NULL, title = "World map", legend_range = @@ -93,12 +94,25 @@ plotmap2 <- function(data, file = NULL, title = "World map", legend_range = }) } if (any(unlist(lapply(data, function(x) return(is.null(attr(x, "coordinates"))))))) { + if (length(getItems(data[[1]], dim = 1) == 67420)) { + mapping <- toolGetMappingCoord2Country() + mapping <- setNames(do.call(rbind.data.frame, strsplit(unlist(mapping[, "coords"]), '\\.')), + c('lon', 'lat')) + mapping <- apply(mapping, 2, function(y) as.numeric(gsub("p", "\\.", y))) + data <- lapply(data, function(x) { + attr(x, "coordinates") <-mapping + return(x) + }) + } else if (length(getItems(data[[1]], dim = 1) == 59199)) { data <- lapply(data, function(x) { - attr(x, "coordinates") <- getCoordinates(degree = TRUE) - return(x) - }) - warning("Missing coordinates in attributes for at least one MAgPIE object. Added coordinates in default MAgPIE cell order.") + attr(x, "coordinates") <- getCoordinates(degree = TRUE) + return(x) + }) + } + warning("Missing coordinates in attributes for at least one MAgPIE object. Added coordinates in default MAgPIE cell order.") } + + data <- as.ggplot(data, asDate = FALSE) if (legend_discrete) { if (is.null(legend_breaks)) { diff --git a/README.md b/README.md index 7bb7d48..f613d5c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Landuse Plot Library -R package **luplot**, version **3.61.0** +R package **luplot**, version **3.61.1** [![CRAN status](https://www.r-pkg.org/badges/version/luplot)](https://cran.r-project.org/package=luplot) [![R build status](https://github.com/pik-piam/luplot/workflows/check/badge.svg)](https://github.com/pik-piam/luplot/actions) [![codecov](https://codecov.io/gh/pik-piam/luplot/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/luplot) [![r-universe](https://pik-piam.r-universe.dev/badges/luplot)](https://pik-piam.r-universe.dev/builds) @@ -39,16 +39,16 @@ In case of questions / problems please contact Benjamin Bodirsky . +Bodirsky B, Dietrich J, Krause M, Stevanovic M, Humpenoeder F, Weindl I, Baumstark L, Klein D, Rolinski S, Wang X, Chen D (2024). _luplot: Landuse Plot Library_. R package version 3.61.1, . A BibTeX entry for LaTeX users is ```latex @Manual{, title = {luplot: Landuse Plot Library}, - author = {Benjamin Leon Bodirsky and Jan Philipp Dietrich and Michael Krause and Miodrag Stevanovic and Florian Humpenoeder and Isabelle Weindl and Lavinia Baumstark and David Klein and Susanne Rolinski and Xiaoxi Wang}, + author = {Benjamin Leon Bodirsky and Jan Philipp Dietrich and Michael Krause and Miodrag Stevanovic and Florian Humpenoeder and Isabelle Weindl and Lavinia Baumstark and David Klein and Susanne Rolinski and Xiaoxi Wang and David Chen}, year = {2024}, - note = {R package version 3.61.0}, + note = {R package version 3.61.1}, url = {https://github.com/pik-piam/luplot}, } ``` diff --git a/man/plotmap2.Rd b/man/plotmap2.Rd index e8cb5d0..663498d 100644 --- a/man/plotmap2.Rd +++ b/man/plotmap2.Rd @@ -89,5 +89,5 @@ Makes use of ggplot2 map plotting capabilites \code{\link{plotmap}} } \author{ -Florian Humpenoeder +Florian Humpenoeder, David M Chen }