diff --git a/.buildlibrary b/.buildlibrary index 18dc6ee..0d909a5 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '70762496' +ValidationKey: '70821675' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/CITATION.cff b/CITATION.cff index 183c879..037efb1 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.58.4 -date-released: '2024-01-22' +version: 3.58.5 +date-released: '2024-02-02' abstract: Some useful functions to plot data such as a map plot function for MAgPIE objects. authors: diff --git a/DESCRIPTION b/DESCRIPTION index 9a0dcfd..f1e74d0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: luplot Title: Landuse Plot Library -Version: 3.58.4 -Date: 2024-01-22 +Version: 3.58.5 +Date: 2024-02-02 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"), @@ -45,4 +45,4 @@ Suggests: covr Encoding: UTF-8 LazyData: no -RoxygenNote: 7.3.0 +RoxygenNote: 7.3.1 diff --git a/R/plotCorrHist2D.R b/R/plotCorrHist2D.R index 87b8f18..745c572 100644 --- a/R/plotCorrHist2D.R +++ b/R/plotCorrHist2D.R @@ -24,6 +24,8 @@ #' @param TitleFontSize Font size of title of correlation plot #' @param legendTitleFont Font size of the title of the legend #' @param legendTextFont Font size of legend +#' @param table Conditional to include table with statistics in the output. TRUE (includes it), FALSE (it doesn't) +#' @param stat Conditional to include R2 and MAE on the fiure. TRUE (includes it), FALSE (it doesn't) #' @author Edna Molina Bacca #' @importFrom grDevices colorRampPalette #' @importFrom ggplot2 ggplot aes_ xlim ylim scale_fill_gradientn coord_fixed geom_abline geom_vline geom_hline @@ -40,7 +42,8 @@ #' plotCorrHist2D <- function(x, y, title = NULL, xlab = "x", ylab = "y", bins = 40, limx=NULL, limy=NULL, folder = NULL, file = "", breaks = waiver(),nrows=2, ncols=2, axisFont=13, - axisTitleFont=13,TitleFontSize=15,legendTitleFont=12,legendTextFont=10,statFont=4) { + axisTitleFont=13,TitleFontSize=15,legendTitleFont=12,legendTextFont=10, + statFont=4, table=FALSE, stat=TRUE) { getNames(x) <- gsub(x = getNames(x), pattern = "\\.", replacement = "_") @@ -114,9 +117,9 @@ plotCorrHist2D <- function(x, y, title = NULL, xlab = "x", ylab = "y", bins = 40 legend.title = element_text(size = legendTitleFont), legend.background = element_blank()) - plots[[tag]] <- plots[[tag]] + annotate("label", size = statFont, x = labelX, y = labelY, + plots[[tag]] <- if(stat) plots[[tag]] + annotate("label", size = statFont, x = labelX, y = labelY, label = paste0("R2 = ", r2), hjust = 1) - plots[[tag]] <- plots[[tag]] + annotate("label", size = statFont, x = labelX, y = labelY2, + plots[[tag]] <- if(stat) plots[[tag]] + annotate("label", size = statFont, x = labelX, y = labelY2, label = paste0("MAE = ", mae), hjust = 1) plots[[tag]] <- if (!is.null(limx)) plots[[tag]] + scale_x_continuous(limits = limx) else plots[[tag]] + scale_x_continuous(limits = limx1) plots[[tag]] <- if (!is.null(limy)) plots[[tag]] + scale_y_continuous(limits = limy) else plots[[tag]] + scale_y_continuous(limits = limy1) @@ -132,5 +135,6 @@ plotCorrHist2D <- function(x, y, title = NULL, xlab = "x", ylab = "y", bins = 40 write.csv2(corr,paste0(folder, file, "_stats.csv")) } - return(plots) + out <- if (table) list(plots,corr) else plots + return(out) } diff --git a/README.md b/README.md index fcfd466..58cb33f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Landuse Plot Library -R package **luplot**, version **3.58.4** +R package **luplot**, version **3.58.5** [![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,7 +39,7 @@ 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 (2024). _luplot: Landuse Plot Library_. R package version 3.58.5, . A BibTeX entry for LaTeX users is @@ -48,7 +48,7 @@ A BibTeX entry for LaTeX users is 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}, year = {2024}, - note = {R package version 3.58.4}, + note = {R package version 3.58.5}, url = {https://github.com/pik-piam/luplot}, } ```