cluster_selection_plot: Justify the number of clusters (silhouette + elbow / scree)

View source: R/manuscript-viz.R

cluster_selection_plotR Documentation

Justify the number of clusters (silhouette + elbow / scree)

Description

For a fused dissimilarity (or a fitted result, or a List of sources) compute, over a range of k, the average silhouette width and the total within-cluster dispersion (an elbow / scree curve), and plot them so the chosen k can be justified in the manuscript.

Usage

cluster_selection_plot(
  x,
  k_range = 2:8,
  linkage = "ward.D2",
  select = c("both", "elbow", "silhouette"),
  plot = TRUE,
  point_size = 2.6,
  base_size = 13
)

Arguments

x

A fitted result (with $DistM), a dissimilarity matrix, or a List of data sources (objects in rows).

k_range

Integer vector of candidate cluster counts.

linkage

Agglomeration method used to cut the dissimilarity.

select

Which criterion to show and use for best_k: "both" (default) draws both panels and picks k from the elbow; "elbow" draws only the within-cluster dispersion (scree) curve and uses its knee; "silhouette" draws only the silhouette curve and uses its maximum. Passing a single criterion therefore shows a single panel.

plot

Logical; draw the figure.

point_size

Marker size for the curve points.

base_size

Base font size for the ggplot2 theme.

Value

Invisibly a data frame with k, silhouette and within_dispersion, plus attributes "best_k", "elbow_k", "silhouette_k" and "plot" (the ggplot object).

See Also

embedding_plot, SelectnrClusters

Examples

data(mosaic_toy)
fit <- M_ABC(mosaic_toy$List, numsim = 40, NC = 3)
cluster_selection_plot(fit, k_range = 2:6, select = "elbow")   # one panel

MosaiClusteR documentation built on Oct. 25, 2026, 1:08 a.m.