Skip to content

Commit

Permalink
update plotmap2 to work with 67k, tmp solution, asggplot still does n…
Browse files Browse the repository at this point in the history
…ot work perfectly
  • Loading branch information
caviddhen committed Mar 19, 2024
1 parent 22afd8c commit 709d4e9
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 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: '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:
Expand Down Expand Up @@ -37,6 +37,9 @@ authors:
- family-names: Wang
given-names: Xiaoxi
email: [email protected]
- family-names: Chen
given-names: David
email: [email protected]
license: LGPL-3.0
repository-code: https://github.com/pik-piam/luplot

10 changes: 6 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre")),
person("Jan Philipp", "Dietrich", , "[email protected]", role = "aut"),
Expand All @@ -13,7 +13,8 @@ Authors@R: c(
person("Lavinia", "Baumstark", , "[email protected]", role = "aut"),
person("David", "Klein", , "[email protected]", role = "aut"),
person("Susanne", "Rolinski", , "[email protected]", role = "aut"),
person("Xiaoxi", "Wang", , "[email protected]", role = "aut")
person("Xiaoxi", "Wang", , "[email protected]", role = "aut"),
person("David", "Chen", , "[email protected]", role = "aut")
)
Maintainer: Benjamin Bodirsky <[email protected]>
Description: Some useful functions to plot data such as a map plot
Expand All @@ -40,7 +41,8 @@ Imports:
rworldmap,
sp,
xml2,
gridExtra
gridExtra,
mrcommons
Suggests:
covr
Encoding: UTF-8
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 19 additions & 5 deletions R/plotmap2.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 =
Expand Down Expand Up @@ -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)) {
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -39,16 +39,16 @@ In case of questions / problems please contact Benjamin Bodirsky <bodirsky@pik-p

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

Bodirsky B, Dietrich J, Krause M, Stevanovic M, Humpenoeder F, Weindl I, Baumstark L, Klein D, Rolinski S, Wang X (2024). _luplot: Landuse Plot Library_. R package version 3.61.0, <URL: https://github.com/pik-piam/luplot>.
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, <URL: https://github.com/pik-piam/luplot>.

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},
}
```
2 changes: 1 addition & 1 deletion man/plotmap2.Rd

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

0 comments on commit 709d4e9

Please sign in to comment.