knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
geohclust offers two functions ?geohclust_poly
and ?geohclust_graph
that enable the clustering of spatial data such as polygons with a hclust type approach but taking advantages of contiguity constraints. The contiguity naturally create a sparsely connected graph that can be leveraged to speed-up the calculations and deal with more than 30000 polygons in seconds.
You can install the development version of geohclust from GitHub with:
# install.packages("devtools") devtools::install_github("comeetie/geohclust")
This is a basic example, we first prepare some spatial polygons data, here the results at the municipality level in one french department for the :
library(geohclust) library(dplyr) library(sf) data("modesshare") deplist = c(37) dep = modesshare |> filter(DEP %in% deplist)
Do the clustering and use the classical function from ?hclust
(?plot.hclust
and ?cutree
):
hc=geohclust_poly(dep) plot(hc) cutree(hc,k=30) |> head(20)
You may also use the ?geocutree
function which build directly a spatial data.frame with the clustering results:
plot(geocutree(hc,k=30))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.