From e57dbcc3c48b6b4015071151944850976de5d0cb Mon Sep 17 00:00:00 2001 From: emolinab Date: Fri, 2 Feb 2024 18:52:27 +0100 Subject: [PATCH] bugfix and new error/fit stat --- .buildlibrary | 2 +- CITATION.cff | 2 +- DESCRIPTION | 2 +- R/plotCorrHist2D.R | 13 ++++++++----- README.md | 6 +++--- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index 0d909a5..8436074 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '70821675' +ValidationKey: '70841430' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/CITATION.cff b/CITATION.cff index 037efb1..3c30c0c 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -2,7 +2,7 @@ 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.5 +version: 3.58.6 date-released: '2024-02-02' abstract: Some useful functions to plot data such as a map plot function for MAgPIE objects. diff --git a/DESCRIPTION b/DESCRIPTION index f1e74d0..3127739 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: luplot Title: Landuse Plot Library -Version: 3.58.5 +Version: 3.58.6 Date: 2024-02-02 Authors@R: c( person("Benjamin Leon", "Bodirsky", , "bodirsky@pik-potsdam.de", role = c("aut", "cre")), diff --git a/R/plotCorrHist2D.R b/R/plotCorrHist2D.R index 745c572..c2b018b 100644 --- a/R/plotCorrHist2D.R +++ b/R/plotCorrHist2D.R @@ -64,7 +64,7 @@ plotCorrHist2D <- function(x, y, title = NULL, xlab = "x", ylab = "y", bins = 40 plotMagpie <- reshape(plotMagpie, direction = "wide", idvar = c("Cell", "Region", "Year"), timevar = "Data1") plots <- list() - corr <- c("Year", "r2", "MAE", "Willmott refined", "Bias") + corr <- c("Year","Variable", "r2", "MAE", "Bias", "error per unit") rf <- colorRampPalette(rev(brewer.pal(11, "RdYlBu"))) r <- rf(32) # color palette @@ -94,11 +94,14 @@ plotCorrHist2D <- function(x, y, title = NULL, xlab = "x", ylab = "y", bins = 40 r2 <- round(cor(data[, valueX], data[, valueY])^2, 3) mae <- luplot::qualityMeasure(pd = data[, valueY], od = data[, valueX], measures = "MAE", p_value = FALSE) - will <- luplot::qualityMeasure(pd = data[, valueY], od = data[, valueX], measures = "Willmott refined", p_value = FALSE) relativeError <- (data[, valueY] - data[, valueX]) / data[, valueX] relativeError[!is.finite(relativeError)] <- NA bias <- sum(relativeError * 100, na.rm = TRUE) / length(relativeError[is.finite(relativeError)]) - all <- t(c(year, r2, mae, will, bias)) + absoluteError <- abs(data[, valueY] - data[, valueX]) + error <- round(sum(absoluteError) / sum(data[, valueX]), 3) + + all <- t(c(year,na, r2, mae, bias,error)) + corr <- rbind(corr, all) tag <- paste0(na, "-", year) @@ -118,9 +121,9 @@ plotCorrHist2D <- function(x, y, title = NULL, xlab = "x", ylab = "y", bins = 40 legend.background = element_blank()) plots[[tag]] <- if(stat) plots[[tag]] + annotate("label", size = statFont, x = labelX, y = labelY, - label = paste0("R2 = ", r2), hjust = 1) + label = paste0("R2 = ", r2), hjust = 1) else plots[[tag]] plots[[tag]] <- if(stat) plots[[tag]] + annotate("label", size = statFont, x = labelX, y = labelY2, - label = paste0("MAE = ", mae), hjust = 1) + label = paste0("MAE = ", mae), hjust = 1) else plots[[tag]] 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) diff --git a/README.md b/README.md index 58cb33f..975e9b6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Landuse Plot Library -R package **luplot**, version **3.58.5** +R package **luplot**, version **3.58.6** [![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.6, . 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.5}, + note = {R package version 3.58.6}, url = {https://github.com/pik-piam/luplot}, } ```