Skip to content

Commit

Permalink
lint signatures of currently unused funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-sauer committed May 28, 2024
1 parent c279cdb commit c2ed894
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '7967870'
ValidationKey: '7948400'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
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: 4.0.1
date-released: '2024-05-27'
version: 4.0.0
date-released: '2024-05-28'
abstract: Some useful functions to plot data such as a map plot function for MAgPIE
objects.
authors:
Expand Down Expand Up @@ -40,6 +40,9 @@ authors:
- family-names: Chen
given-names: David
email: [email protected]
- family-names: Sauer
given-names: Pascal
email: [email protected]
license: LGPL-3.0
repository-code: https://github.com/pik-piam/luplot

9 changes: 5 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: 4.0.1
Date: 2024-05-27
Version: 4.0.0
Date: 2024-05-28
Authors@R: c(
person("Benjamin Leon", "Bodirsky", , "[email protected]", role = c("aut", "cre")),
person("Jan Philipp", "Dietrich", , "[email protected]", role = "aut"),
Expand All @@ -14,7 +14,8 @@ Authors@R: c(
person("David", "Klein", , "[email protected]", role = "aut"),
person("Susanne", "Rolinski", , "[email protected]", role = "aut"),
person("Xiaoxi", "Wang", , "[email protected]", role = "aut"),
person("David", "Chen", , "[email protected]", role = "aut")
person("David", "Chen", , "[email protected]", role = "aut"),
person("Pascal", "Sauer", , "[email protected]", role = "aut")
)
Maintainer: Benjamin Bodirsky <[email protected]>
Description: Some useful functions to plot data such as a map plot
Expand All @@ -30,13 +31,13 @@ Imports:
graphics,
grDevices,
gridExtra,
lusweave,
mip,
mstools (>= 0.6.0),
quitte,
RColorBrewer,
reshape2,
rworldmap (>= 1.3.8),
lusweave,
utils
Suggests:
covr
Expand Down
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(aggregate_for_plot)
export(aggregateForPlot)
export(as.ggplot)
export(deco_plot)
export(gginput)
Expand All @@ -12,6 +12,7 @@ export(plotcountrymap)
export(plotmap2)
export(plotregionscluster)
export(qualityMeasure)
export(showcolors)
export(swoutput)
export(whereplot)
import(magclass)
Expand All @@ -23,6 +24,7 @@ importFrom(ggplot2,aes_string)
importFrom(ggplot2,annotate)
importFrom(ggplot2,coord_cartesian)
importFrom(ggplot2,coord_fixed)
importFrom(ggplot2,coord_flip)
importFrom(ggplot2,element_blank)
importFrom(ggplot2,element_line)
importFrom(ggplot2,element_rect)
Expand Down
30 changes: 15 additions & 15 deletions R/aggregate_for_plot.R → R/aggregateForPlot.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#' aggregate_for_plot
#' aggregateForPlot
#'
#' Aggregates Data for an area chart. The value of all underlying
#' regions/years/timesteps are added to the value of the current
#' region/year/timestep.
#'
#'
#' @usage aggregate_for_plot(plotdata,
#' dimension="region",region_plotorder=NULL)
#' @usage aggregateForPlot(plotdata,
#' dimension="region",regionPlotorder=NULL)
#' @param plotdata An MAgPIE object
#' @param dimension by "region", "name" or "year"
#' @param region_plotorder allows to change the order of the regions by giving
#' @param regionPlotorder allows to change the order of the regions by giving
#' a vector with the order
#' @return A MAgPIE object of the same dimensions as plotdata
#' @author Benjamin Bodirsky
Expand All @@ -19,34 +19,34 @@
#' #no aggregation
#' scratch_plot(population_magpie[,,2])
#' #aggregation
#' scratch_plot(aggregate_for_plot(population_magpie[,,2],region_plotorder=c(10,1:9)))
#' scratch_plot(aggregateForPlot(population_magpie[,,2],regionPlotorder=c(10,1:9)))
#' }
#' @export
#' @importFrom magclass getRegions setCells getCells getNames<- getYears getYears<- getRegions<- getNames

aggregate_for_plot<-function(plotdata, dimension="region", region_plotorder=NULL)
aggregateForPlot<-function(plotdata, dimension="region", regionPlotorder=NULL)
{
#dimension="region"
#data(population_magpie)
#plotdata<-population_magpie
#plot_order=NULL
#region_plotorder=c(1,3,4,5,6,7,8,9,10,2)
if (is.null(region_plotorder)) {
region_plotorder=1:dim(plotdata)[1]
} else if(length(region_plotorder)!=dim(plotdata)[1]){stop("plotorder has to be vector with the length of dim(plotdata)[1]")}
#regionPlotorder=c(1,3,4,5,6,7,8,9,10,2)
if (is.null(regionPlotorder)) {
regionPlotorder=1:dim(plotdata)[1]
} else if(length(regionPlotorder)!=dim(plotdata)[1]){stop("plotorder has to be vector with the length of dim(plotdata)[1]")}
if(magpieResolution(plotdata)=="cell") {stop("Cellular datasets are not supported")}
if (dimension=="region") {
aggregateplotdata<-plotdata[1,,]*0
plotdata_out<-plotdata*0
dimnames(plotdata_out)[[1]]<-paste(getRegions(plotdata)[region_plotorder],1:dim(plotdata)[1],sep=".")
for (region_dimension in getRegions(plotdata)[region_plotorder]) {
dimnames(plotdata_out)[[1]]<-paste(getRegions(plotdata)[regionPlotorder],1:dim(plotdata)[1],sep=".")
for (region_dimension in getRegions(plotdata)[regionPlotorder]) {
plotdata_out[region_dimension,,] <- setCells(aggregateplotdata,getCells(plotdata[region_dimension,,])) + plotdata[region_dimension,,]
aggregateplotdata<-plotdata_out[region_dimension,,]
}
} else if (dimension=="name") {
aggregateplotdata<-plotdata[,,1]*0
for (name_dimension in getNames(plotdata)) {
getNames(aggregate_for_plot) <- name_dimension
getNames(aggregateForPlot) <- name_dimension
plotdata_out[,,name_dimension] <- aggregateplotdata + plotdata[,,name_dimension]
aggregateplotdata<-plotdata_out[,,name_dimension]
}
Expand All @@ -60,8 +60,8 @@ aggregate_for_plot<-function(plotdata, dimension="region", region_plotorder=NULL
} else if (dimension=="region_name") {
aggregateplotdata<-plotdata[1,,1]*0
plotdata_out<-plotdata*0
dimnames(plotdata_out)[[1]]<-paste(getRegions(plotdata)[region_plotorder],1:dim(plotdata)[1],sep=".")
for (region_dimension in getRegions(plotdata)[region_plotorder]) {
dimnames(plotdata_out)[[1]]<-paste(getRegions(plotdata)[regionPlotorder],1:dim(plotdata)[1],sep=".")
for (region_dimension in getRegions(plotdata)[regionPlotorder]) {
getRegions(aggregateplotdata) <- region_dimension
for (name_dimension in getNames(plotdata)) {
plotdata_out[region_dimension,,name_dimension] <- setCells(aggregateplotdata,getCells(plotdata[region_dimension,,])) + plotdata[region_dimension,,name_dimension]
Expand Down
34 changes: 34 additions & 0 deletions R/showcolors.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#' Creates bar plot to display given colors
#'
#' For a quick translation of hexadecimal color codes into visible colors this
#' function simply creates a bar plot with the hexadecimal colors specified by
#' the user. It takes a vector of strings containing the hexadecimal color
#' codes, e.g. "#D0DD1E".
#'
#' @usage showcolors(...)
#' @param ... One ore more strings or a vector of strings containing
#' hexadecimal color codes.
#' @author David Klein
#' @examples
#'
#' \dontrun{showcolors("#D0DD1E")}
#' \dontrun{showcolors("#beefee")}
#' \dontrun{showcolors(c("#beefee","#D0DD1E"),"#FFFFFF")}
#' @importFrom ggplot2 coord_flip
#' @export
showcolors <- function(...) {
colors <- c(...)
labels <- colors
# if ... is a named vector add names to the labels
if(!is.null(names(colors))) labels <- paste(names(colors),colors,sep="\n")
# create data frame
df<-data.frame(x=labels, c=colors)
# prevent ggplot from sorting it alphabetically by giving order explicitly here
# using original order of rownames. Reversing it because the bar plot reverses it again
# To yield the correct mapping between colors and labels the colors have to be also reversed
df$x<-factor(df$x,levels=rev(labels))
# create bar plot
p1 <- ggplot(data=df, aes_string(x="x")) + geom_bar(fill=rev(df$c)) + coord_flip() + theme(axis.title.x = element_blank(),axis.title.y = element_blank())
#print(p1)
return(p1)
}
27 changes: 14 additions & 13 deletions R/swoutput.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#' rescaled for fitting on portrait pages.
#'
#' @usage
#' swoutput(stream,data,unit="unit",plot=TRUE,table=TRUE,scenario_name="default",
#' text_size=16,digits=0,plot_level=NULL,...)
#' swoutput(stream,data,unit="unit",plot=TRUE,table=TRUE,scenarioName="default",
#' textSize=16,digits=0,plotLevel=NULL,...)
#' @param stream The \code{swStream} object to be modified
#' @param data MAgPIE object or list of MAgPIE objects. For a list of MAgPIE
#' objects the name of the list entry (has to be character) is used as scenario
Expand All @@ -22,11 +22,11 @@
#' (\code{\link[luplot]{magpie2ggplot2}}) is added
#' @param table TRUE or FALSE. If TRUE, LaTeX code for data table
#' (\code{\link[xtable]{print.xtable}}) is added
#' @param scenario_name Name of the scenario. Only used if data is not a list.
#' @param text_size Size of text used in \code{\link[luplot]{magpie2ggplot2}}
#' @param scenarioName Name of the scenario. Only used if data is not a list.
#' @param textSize Size of text used in \code{\link[luplot]{magpie2ggplot2}}
#' @param digits Number of digits for rounding. Used in
#' \code{\link[xtable]{xtable}}
#' @param plot_level NULL for all (default), reg or glo
#' @param plotLevel NULL for all (default), reg or glo
#' @param ... Further options passed to \code{\link[luplot]{magpie2ggplot2}} and
#' \code{\link[xtable]{print.xtable}}
#' @return No return value
Expand All @@ -45,20 +45,21 @@
#' swoutput(sw,croparea(gdx),"mio. ha",scenario="test")
#' swclose(sw)}
#'
swoutput <- function(stream,data,unit="unit",plot=TRUE,table=TRUE,scenario_name="default",text_size=16,digits=0,plot_level=NULL,...) {
swoutput <- function(stream, data, unit = "unit", plot = TRUE, table = TRUE,
scenarioName = "default", textSize = 16, digits = 0, plotLevel = NULL, ...) {
if (!is.list(data)) {
temp <- data
data <- list()
data[[scenario_name]] <- temp
data[[scenarioName]] <- temp
}
if (is.null(plot_level)) ggdata <- data
else if (plot_level == "reg") {
if (is.null(plotLevel)) ggdata <- data
else if (plotLevel == "reg") {
ggdata <- lapply(data,function(x) x[setdiff(getRegions(x),"GLO"),,])
} else if (plot_level == "glo") {
plot_level <- "GLO"
ggdata <- lapply(data,function(x) x[plot_level,,])
} else if (plotLevel == "glo") {
plotLevel <- "GLO"
ggdata <- lapply(data,function(x) x[plotLevel,,])
}
if (plot) swfigure(stream,print,magpie2ggplot2(data=ggdata,ylab=unit,text_size=text_size,...),sw_option="width=10")
if (plot) swfigure(stream,print,magpie2ggplot2(data=ggdata,ylab=unit,text_size=textSize,...),sw_option="width=10")
if (table) {
for (scenario in names(sapply(data, names))) {
# if (nyears(data[[scenario]]) > 12) {
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 **4.0.1**
R package **luplot**, version **4.0.0**

[![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, Chen D (2024). _luplot: Landuse Plot Library_. R package version 4.0.1, <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, Sauer P (2024). _luplot: Landuse Plot Library_. R package version 4.0.0, <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 and David Chen},
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 and Pascal Sauer},
year = {2024},
note = {R package version 4.0.1},
note = {R package version 4.0.0},
url = {https://github.com/pik-piam/luplot},
}
```
16 changes: 8 additions & 8 deletions man/aggregate_for_plot.Rd → man/aggregateForPlot.Rd

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

27 changes: 27 additions & 0 deletions man/showcolors.Rd

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

10 changes: 5 additions & 5 deletions man/swoutput.Rd

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

0 comments on commit c2ed894

Please sign in to comment.