if (FALSE) {
library(tmap)
## Load the Spain colorectal cancer mortality data ##
data(Carto_SpainMUN)
## Plot of the grouping variable 'region' ##
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)
## Partition + 1st order neighbours ##
carto.k1 <- divide_carto(carto=Carto_SpainMUN, ID.group="region", k=1)
## Partition + 2nd order neighbours ##
carto.k2 <- divide_carto(carto=Carto_SpainMUN, ID.group="region", k=2)
## Plot the spatial polygons for the autonomous region of Castilla y Leon ##
plot(carto.k2$`Castilla y Leon`$geometry, col="dodgerblue4", main="Castilla y Leon")
plot(carto.k1$`Castilla y Leon`$geometry, col="dodgerblue", add=TRUE)
plot(carto.k0$`Castilla y Leon`$geometry, col="lightgrey", add=TRUE)
}
Run the code above in your browser using DataLab