genclust {sfclust} | R Documentation |
Generate clusters for spatial clustering
Description
Creates an undirected graph from spatial polygonal data, computes its minimum spanning
tree (MST), and generates nclust
clusters. This function is used to initialize
cluster membership in a clustering algorithm, such as sfclust
.
Usage
genclust(x, nclust = 10, weights = NULL)
Arguments
x |
An |
nclust |
Integer, specifying the initial number of clusters. |
weights |
Optional |
Value
A list with three elements:
-
graph
: The undirected graph object representing spatial contiguity. -
mst
: The minimum spanning tree. -
membership
: The cluster membership for elements inx
.
Examples
library(sfclust)
library(sf)
x <- st_make_grid(cellsize = c(1, 1), offset = c(0, 0), n = c(3, 2))
# using distance between geometries
clust <- genclust(x, nclust = 3, weights = st_distance(st_centroid(x)))
print(clust)
plot(st_sf(x, cluster = factor(clust$membership)))
# using increasing weights
cluster_ini <- genclust(x, nclust = 3, weights = 1:36)
print(cluster_ini)
plot(st_sf(x, cluster = factor(cluster_ini$membership)))
# using on random weights
cluster_ini <- genclust(x, nclust = 3, weights = runif(36))
print(cluster_ini)
plot(st_sf(x, cluster = factor(cluster_ini$membership)))