From a21077034410f58b161bae75685cc7c45011dbad Mon Sep 17 00:00:00 2001 From: carlesmila Date: Tue, 12 Mar 2024 09:23:49 +0100 Subject: [PATCH 1/2] Fix x axis in plot.nndm when phi="max" --- R/plot.R | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/R/plot.R b/R/plot.R index a166c70e..ec9ce36f 100644 --- a/R/plot.R +++ b/R/plot.R @@ -116,8 +116,16 @@ plot.nndm <- function(x, ...){ val=sum(x$Gj<=x$phi)/length(x$Gj))) Gj_df$Function <- "3_Gj(r)" - # Merge data for plotting - Gplot <- rbind(Gij_df, Gjstar_df, Gj_df) + # Merge data for plotting, get maxdist relevant for plotting + if(any(Gj_df$val==1)&any(Gjstar_df$val==1)&any(Gij_df$val==1)){ + Gplot <- rbind(Gij_df, Gjstar_df, Gj_df) + maxdist <- max(Gplot$r[Gplot$val!=1]) + 1e-9 + Gplot <- Gplot[Gplot$r <= maxdist,] + Gplot <- rbind(Gplot, data.frame(r=maxdist, val=1, + Function = c("1_Gij(r)", "2_Gjstar(r)", "3_Gj(r)"))) + }else{ + Gplot <- rbind(Gij_df, Gjstar_df, Gj_df) + } # Plot ggplot2::ggplot(Gplot) + From 157601eadd2bc1a22e7555394e1fbd7e464ac0f9 Mon Sep 17 00:00:00 2001 From: carlesmila Date: Tue, 12 Mar 2024 09:36:25 +0100 Subject: [PATCH 2/2] fixed error in tests for geographic differences in nndm and knndm --- tests/testthat/test-knndm.R | 4 ++++ tests/testthat/test-nndm.R | 2 ++ 2 files changed, 6 insertions(+) diff --git a/tests/testthat/test-knndm.R b/tests/testthat/test-knndm.R index 88676960..f22f937a 100644 --- a/tests/testthat/test-knndm.R +++ b/tests/testthat/test-knndm.R @@ -1,5 +1,6 @@ test_that("kNNDM works with geographical coordinates and prediction points", { + sf::sf_use_s2(TRUE) aoi <- sf::st_as_sfc("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", crs="epsg:4326") tpoints <- sf::st_as_sfc("MULTIPOINT ((1 1), (1 2), (2 2), (2 3), (1 4), (5 4))", crs="epsg:4326") |> sf::st_cast("POINT") @@ -72,6 +73,7 @@ test_that("kNNDM works with modeldomain and projected coordinates", { test_that("kNNDM works with modeldomain and geographical coordinates", { + sf::sf_use_s2(TRUE) aoi <- sf::st_as_sfc("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", crs="epsg:4326") tpoints <- sf::st_as_sfc("MULTIPOINT ((1 1), (1 2), (2 2), (2 3), (1 4), (5 4))", crs="epsg:4326") |> sf::st_cast("POINT") @@ -108,6 +110,7 @@ test_that("kNNDM works with modeldomain and no crs", { test_that("kNNDM works when no clustering is present", { + sf::sf_use_s2(TRUE) aoi <- sf::st_as_sfc("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", crs="epsg:25832") set.seed(1) @@ -166,6 +169,7 @@ test_that("kNNDM works with many points and different configurations", { test_that("kNNDM recognizes erroneous input", { + sf::sf_use_s2(TRUE) aoi <- sf::st_as_sfc("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", crs="epsg:25832") tpoints <- sf::st_as_sfc("MULTIPOINT ((1 1), (1 2), (2 2), (2 3), (1 4), (5 4))", crs="epsg:25832") |> sf::st_cast("POINT") diff --git a/tests/testthat/test-nndm.R b/tests/testthat/test-nndm.R index ee01a705..3913133d 100644 --- a/tests/testthat/test-nndm.R +++ b/tests/testthat/test-nndm.R @@ -44,6 +44,7 @@ test_that("NNDM detects wrong data and geometry types", { test_that("NNDM detects different CRS in inputs", { + sf::sf_use_s2(TRUE) set.seed(1234) poly <- sf::st_polygon(list(matrix(c(0,0,0,50,50,50,50,0,0,0), ncol=2, byrow=TRUE))) @@ -91,6 +92,7 @@ test_that("NNDM yields the expected results for all data types", { test_that("NNDM yields the expected results for all CRS", { + sf::sf_use_s2(TRUE) set.seed(1234) poly <- sf::st_polygon(list(matrix(c(0,0,0,50,50,50,50,0,0,0), ncol=2, byrow=TRUE)))