From 6e64a099c81b1270c7856d19a84e666142b8f66c Mon Sep 17 00:00:00 2001 From: Aritz Adin Date: Mon, 12 Aug 2024 10:43:23 +0200 Subject: [PATCH] condition for the upcoming release of 'tmap' v4 --- DESCRIPTION | 2 +- NEWS | 1 + R/clustering_partition.R | 22 ++++++++---- R/divide_carto.R | 15 ++++++-- R/random_partition.R | 68 +++++++++++++++++++++++++------------ README.md | 3 +- man/clustering_partition.Rd | 20 ++++++++--- man/divide_carto.Rd | 15 ++++++-- man/random_partition.Rd | 66 ++++++++++++++++++++++++----------- 9 files changed, 152 insertions(+), 60 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 292edc4..08a7e1f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: bigDM Type: Package Title: Scalable Bayesian Disease Mapping Models for High-Dimensional Data Version: 0.5.5 -Date: 2024-06-19 +Date: 2024-08-12 Authors@R: c(person(given = "Aritz", family = "Adin", diff --git a/NEWS b/NEWS index 0560d8e..35effab 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,5 @@ version 0.5.5 (development) +- condition for the upcoming release of 'tmap' v4 - small changes for compatibility with 'spdep' version 1.3-6 - new 'Data_MultiCancer' object diff --git a/R/clustering_partition.R b/R/clustering_partition.R index da58f19..2675033 100644 --- a/R/clustering_partition.R +++ b/R/clustering_partition.R @@ -50,12 +50,22 @@ #' carto.data <- st_set_geometry(carto.new, NULL) #' carto.partition <- aggregate(carto.new[,"geometry"], list(ID.group=carto.data[,"ID.group"]), head) #' -#' tm_shape(carto.new) + -#' tm_polygons(col="ID.group") + -#' tm_shape(carto.partition) + -#' tm_borders(col="black", lwd=2) + -#' tm_layout(legend.outside=TRUE) -#'} +#' tmap4 <- packageVersion("tmap") >= "3.99" +#' +#' if(tmap4){ +#' tm_shape(carto.new) + +#' tm_polygons(fill="ID.group", fill.scale=tm_scale(values="brewer.set3")) + +#' tm_shape(carto.partition) + +#' tm_borders(col="black", lwd=2) + +#' tm_layout(legend.outside=TRUE, legend.frame=FALSE) +#' }else{ +#' tm_shape(carto.new) + +#' tm_polygons(col="ID.group") + +#' tm_shape(carto.partition) + +#' tm_borders(col="black", lwd=2) + +#' tm_layout(legend.outside=TRUE) +#' } +#' } #' #' @export clustering_partition <- function(carto, ID.area=NULL, var=NULL, n.cluster=10, min.size=NULL, W=NULL, l=1, Wk=NULL, distance="euclidean", verbose=TRUE){ diff --git a/R/divide_carto.R b/R/divide_carto.R index e3bc844..250f019 100644 --- a/R/divide_carto.R +++ b/R/divide_carto.R @@ -24,9 +24,18 @@ #' data(Carto_SpainMUN) #' #' ## Plot of the grouping variable 'region' ## -#' tm_shape(Carto_SpainMUN) + -#' tm_polygons(col="region") + -#' tm_layout(legend.outside=TRUE) +#' tmap4 <- packageVersion("tmap") >= "3.99" +#' +#' if(tmap4){ +#' tm_shape(Carto_SpainMUN) + +#' tm_polygons(fill="region", +#' fill.scale=tm_scale(values="brewer.set3"), +#' fill.legend=tm_legend(frame=FALSE)) +#' }else{ +#' tm_shape(Carto_SpainMUN) + +#' tm_polygons(col="region") + +#' tm_layout(legend.outside=TRUE) +#' } #' #' ## Disjoint partition ## #' carto.k0 <- divide_carto(carto=Carto_SpainMUN, ID.group="region", k=0) diff --git a/R/random_partition.R b/R/random_partition.R index 9cb66f9..256bb6e 100644 --- a/R/random_partition.R +++ b/R/random_partition.R @@ -25,6 +25,7 @@ #' @examples #' \dontrun{ #' library(tmap) +#' tmap4 <- packageVersion("tmap") >= "3.99" #' #' ## Load the Spain colorectal cancer mortality data ## #' data(Carto_SpainMUN) @@ -36,13 +37,21 @@ #' #' part1 <- aggregate(carto.r1[,"geometry"], by=list(ID.group=carto.r1$ID.group), head) #' -#' tm_shape(carto.r1) + -#' tm_polygons(col="ID.group") + -#' tm_shape(part1) + tm_borders(col="black", lwd=2) + -#' tm_layout(main.title="3x3 regular grid (with no size restrictions)", -#' main.title.position="center", main.title.size=1, -#' legend.outside=TRUE) -#' +#' if(tmap4){ +#' tm_shape(carto.r1) + +#' tm_polygons(fill="ID.group", +#' fill.scale=tm_scale(values="brewer.set3"), +#' fill.legend=tm_legend(frame=FALSE)) + +#' tm_shape(part1) + tm_borders(col="black", lwd=2) + +#' tm_title(text="3x3 regular grid (with no size restrictions)") +#' }else{ +#' tm_shape(carto.r1) + +#' tm_polygons(col="ID.group") + +#' tm_shape(part1) + tm_borders(col="black", lwd=2) + +#' tm_layout(main.title="3x3 regular grid (with no size restrictions)", +#' main.title.position="center", main.title.size=1, +#' legend.outside=TRUE) +#' } #' #' ## Random partition based on a 6x4 regular grid (with size restrictions) ## #' carto.r2 <- random_partition(carto=Carto_SpainMUN, rows=6, columns=4, @@ -51,13 +60,21 @@ #' #' part2 <- aggregate(carto.r2[,"geometry"], by=list(ID.group=carto.r2$ID.group), head) #' -#' tm_shape(carto.r2) + -#' tm_polygons(col="ID.group") + -#' tm_shape(part2) + tm_borders(col="black", lwd=2) + -#' tm_layout(main.title="6x4 regular grid (min.size=50, max.size=600)", -#' main.title.position="center", main.title.size=1, -#' legend.outside=TRUE) -#' +#' if(tmap4){ +#' tm_shape(carto.r2) + +#' tm_polygons(fill="ID.group", +#' fill.scale=tm_scale(values="brewer.set3"), +#' fill.legend=tm_legend(frame=FALSE)) + +#' tm_shape(part2) + tm_borders(col="black", lwd=2) + +#' tm_title(text="6x4 regular grid (min.size=50, max.size=600)") +#' }else{ +#' tm_shape(carto.r2) + +#' tm_polygons(col="ID.group") + +#' tm_shape(part2) + tm_borders(col="black", lwd=2) + +#' tm_layout(main.title="6x4 regular grid (min.size=50, max.size=600)", +#' main.title.position="center", main.title.size=1, +#' legend.outside=TRUE) +#' } #' #' ## Random partition based on a 6x4 regular grid (with size and proportion of zero restrictions) ## #' carto.r3 <- random_partition(carto=Carto_SpainMUN, rows=6, columns=4, @@ -66,12 +83,21 @@ #' #' part3 <- aggregate(carto.r3[,"geometry"], by=list(ID.group=carto.r3$ID.group), head) #' -#' tm_shape(carto.r3) + -#' tm_polygons(col="ID.group") + -#' tm_shape(part3) + tm_borders(col="black", lwd=2) + -#' tm_layout(main.title="6x4 regular grid (min.size=50, max.size=600, prop.zero=0.5)", -#' main.title.position="center", main.title.size=1, -#' legend.outside=TRUE) +#' if(tmap4){ +#' tm_shape(carto.r3) + +#' tm_polygons(fill="ID.group", +#' fill.scale=tm_scale(values="brewer.set3"), +#' fill.legend=tm_legend(frame=FALSE)) + +#' tm_shape(part3) + tm_borders(col="black", lwd=2) + +#' tm_title(text="6x4 regular grid (min.size=50, max.size=600, prop.zero=0.5)") +#' }else{ +#' tm_shape(carto.r3) + +#' tm_polygons(col="ID.group") + +#' tm_shape(part3) + tm_borders(col="black", lwd=2) + +#' tm_layout(main.title="6x4 regular grid (min.size=50, max.size=600, prop.zero=0.5)", +#' main.title.position="center", main.title.size=1, +#' legend.outside=TRUE) +#' } #' } #' #' @export @@ -182,7 +208,7 @@ random_partition <- function(carto, rows=3, columns=3, min.size=50, max.size=100 if(any(table(carto$ID.group)>max.size)) warning(sprintf("%d subregion(s) have more than %d areas",sum(table(carto$ID.group)>max.size),max.size), call.=FALSE) - carto$ID.group <- as.character(carto$ID.group) + # carto$ID.group <- as.character(carto$ID.group) return(carto) } diff --git a/README.md b/README.md index 43e65ac..30bf970 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,8 @@ When using this package, please cite the following papers: ``` news(package="bigDM") ``` -__Changes in version 0.5.5__ (2024 Jun 19) +__Changes in version 0.5.5__ (2024 Aug 12) +* condition for the upcoming release of `tmap` v4 * small changes for compatibility with `spdep` version 1.3-6 * new `Data_MultiCancer` object diff --git a/man/clustering_partition.Rd b/man/clustering_partition.Rd index 560cc48..19edcba 100644 --- a/man/clustering_partition.Rd +++ b/man/clustering_partition.Rd @@ -69,11 +69,21 @@ table(carto.new$ID.group) carto.data <- st_set_geometry(carto.new, NULL) carto.partition <- aggregate(carto.new[,"geometry"], list(ID.group=carto.data[,"ID.group"]), head) -tm_shape(carto.new) + - tm_polygons(col="ID.group") + - tm_shape(carto.partition) + - tm_borders(col="black", lwd=2) + - tm_layout(legend.outside=TRUE) +tmap4 <- packageVersion("tmap") >= "3.99" + +if(tmap4){ + tm_shape(carto.new) + + tm_polygons(fill="ID.group", fill.scale=tm_scale(values="brewer.set3")) + + tm_shape(carto.partition) + + tm_borders(col="black", lwd=2) + + tm_layout(legend.outside=TRUE, legend.frame=FALSE) +}else{ + tm_shape(carto.new) + + tm_polygons(col="ID.group") + + tm_shape(carto.partition) + + tm_borders(col="black", lwd=2) + + tm_layout(legend.outside=TRUE) +} } } diff --git a/man/divide_carto.Rd b/man/divide_carto.Rd index 0569b89..65829a0 100644 --- a/man/divide_carto.Rd +++ b/man/divide_carto.Rd @@ -31,9 +31,18 @@ library(tmap) data(Carto_SpainMUN) ## Plot of the grouping variable 'region' ## -tm_shape(Carto_SpainMUN) + - tm_polygons(col="region") + - tm_layout(legend.outside=TRUE) +tmap4 <- packageVersion("tmap") >= "3.99" + +if(tmap4){ + tm_shape(Carto_SpainMUN) + + tm_polygons(fill="region", + fill.scale=tm_scale(values="brewer.set3"), + fill.legend=tm_legend(frame=FALSE)) +}else{ + tm_shape(Carto_SpainMUN) + + tm_polygons(col="region") + + tm_layout(legend.outside=TRUE) +} ## Disjoint partition ## carto.k0 <- divide_carto(carto=Carto_SpainMUN, ID.group="region", k=0) diff --git a/man/random_partition.Rd b/man/random_partition.Rd index 0312f2e..897dcd3 100644 --- a/man/random_partition.Rd +++ b/man/random_partition.Rd @@ -45,6 +45,7 @@ Finally, if \code{prop.zero} argument is set, the subregions with proportion of \examples{ \dontrun{ library(tmap) +tmap4 <- packageVersion("tmap") >= "3.99" ## Load the Spain colorectal cancer mortality data ## data(Carto_SpainMUN) @@ -56,13 +57,21 @@ table(carto.r1$ID.group) part1 <- aggregate(carto.r1[,"geometry"], by=list(ID.group=carto.r1$ID.group), head) -tm_shape(carto.r1) + - tm_polygons(col="ID.group") + - tm_shape(part1) + tm_borders(col="black", lwd=2) + - tm_layout(main.title="3x3 regular grid (with no size restrictions)", - main.title.position="center", main.title.size=1, - legend.outside=TRUE) - +if(tmap4){ + tm_shape(carto.r1) + + tm_polygons(fill="ID.group", + fill.scale=tm_scale(values="brewer.set3"), + fill.legend=tm_legend(frame=FALSE)) + + tm_shape(part1) + tm_borders(col="black", lwd=2) + + tm_title(text="3x3 regular grid (with no size restrictions)") +}else{ + tm_shape(carto.r1) + + tm_polygons(col="ID.group") + + tm_shape(part1) + tm_borders(col="black", lwd=2) + + tm_layout(main.title="3x3 regular grid (with no size restrictions)", + main.title.position="center", main.title.size=1, + legend.outside=TRUE) +} ## Random partition based on a 6x4 regular grid (with size restrictions) ## carto.r2 <- random_partition(carto=Carto_SpainMUN, rows=6, columns=4, @@ -71,13 +80,21 @@ table(carto.r2$ID.group) part2 <- aggregate(carto.r2[,"geometry"], by=list(ID.group=carto.r2$ID.group), head) -tm_shape(carto.r2) + - tm_polygons(col="ID.group") + - tm_shape(part2) + tm_borders(col="black", lwd=2) + - tm_layout(main.title="6x4 regular grid (min.size=50, max.size=600)", - main.title.position="center", main.title.size=1, - legend.outside=TRUE) - +if(tmap4){ + tm_shape(carto.r2) + + tm_polygons(fill="ID.group", + fill.scale=tm_scale(values="brewer.set3"), + fill.legend=tm_legend(frame=FALSE)) + + tm_shape(part2) + tm_borders(col="black", lwd=2) + + tm_title(text="6x4 regular grid (min.size=50, max.size=600)") +}else{ + tm_shape(carto.r2) + + tm_polygons(col="ID.group") + + tm_shape(part2) + tm_borders(col="black", lwd=2) + + tm_layout(main.title="6x4 regular grid (min.size=50, max.size=600)", + main.title.position="center", main.title.size=1, + legend.outside=TRUE) +} ## Random partition based on a 6x4 regular grid (with size and proportion of zero restrictions) ## carto.r3 <- random_partition(carto=Carto_SpainMUN, rows=6, columns=4, @@ -86,12 +103,21 @@ table(carto.r3$ID.group) part3 <- aggregate(carto.r3[,"geometry"], by=list(ID.group=carto.r3$ID.group), head) -tm_shape(carto.r3) + - tm_polygons(col="ID.group") + - tm_shape(part3) + tm_borders(col="black", lwd=2) + - tm_layout(main.title="6x4 regular grid (min.size=50, max.size=600, prop.zero=0.5)", - main.title.position="center", main.title.size=1, - legend.outside=TRUE) +if(tmap4){ + tm_shape(carto.r3) + + tm_polygons(fill="ID.group", + fill.scale=tm_scale(values="brewer.set3"), + fill.legend=tm_legend(frame=FALSE)) + + tm_shape(part3) + tm_borders(col="black", lwd=2) + + tm_title(text="6x4 regular grid (min.size=50, max.size=600, prop.zero=0.5)") +}else{ + tm_shape(carto.r3) + + tm_polygons(col="ID.group") + + tm_shape(part3) + tm_borders(col="black", lwd=2) + + tm_layout(main.title="6x4 regular grid (min.size=50, max.size=600, prop.zero=0.5)", + main.title.position="center", main.title.size=1, + legend.outside=TRUE) +} } }