Skip to content

Commit

Permalink
condition for the upcoming release of 'tmap' v4
Browse files Browse the repository at this point in the history
  • Loading branch information
aritz-adin committed Aug 12, 2024
1 parent 577df15 commit 6e64a09
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 60 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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

Expand Down
22 changes: 16 additions & 6 deletions R/clustering_partition.R
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
15 changes: 12 additions & 3 deletions R/divide_carto.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
68 changes: 47 additions & 21 deletions R/random_partition.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#' @examples
#' \dontrun{
#' library(tmap)
#' tmap4 <- packageVersion("tmap") >= "3.99"
#'
#' ## Load the Spain colorectal cancer mortality data ##
#' data(Carto_SpainMUN)
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 15 additions & 5 deletions man/clustering_partition.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions man/divide_carto.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 46 additions & 20 deletions man/random_partition.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6e64a09

Please sign in to comment.