Skip to content

Commit

Permalink
bugfix and new error/fit stat
Browse files Browse the repository at this point in the history
  • Loading branch information
emolinab committed Feb 2, 2024
1 parent f581469 commit e57dbcc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '70821675'
ValidationKey: '70841430'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre")),
Expand Down
13 changes: 8 additions & 5 deletions R/plotCorrHist2D.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down
6 changes: 3 additions & 3 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.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)

Expand Down Expand Up @@ -39,7 +39,7 @@ 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.58.5, <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 (2024). _luplot: Landuse Plot Library_. R package version 3.58.6, <URL: https://github.com/pik-piam/luplot>.

A BibTeX entry for LaTeX users is

Expand All @@ -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},
}
```

0 comments on commit e57dbcc

Please sign in to comment.