Overlay centroids via k-means or graph-based clustering

Overylay k-means centroids onto an xy scatter

overlay_knn_centroids(x, y, indices, ...)

overlay_snn_centroids(x, y, indices, ...)

overlay_kmeans_centroids(x, y, num_centers, ...)

Arguments

x

numeric vectors to produce segments from

y

numeric vectors to produce segments from

indices

a neighborSet index matrix

...

additional arguments to pass to ggplot2::geom_segment

num_centers

the number of centroids to estimate

Value

a ggplot2::geom_point layer

Details

The nearest neighbor centroids functions automatically estimate centroids from an indices matrix representing a nearest neighbor graph via a community detection algorithm (louvain) from the igraph package. The smaller the value of ncol(indices) the more centroids there will be. The kmeans method returns the centroids from run stats::kmeans with the user suppplied number of centers.