View source: R/manuscript-viz.R
| cluster_k_sweep | R Documentation |
Rather than only reporting the best k, project the objects to a
fixed 2-D embedding and recolour them by the k-cut for each
candidate k in a grid, annotating the average silhouette per panel. This
makes it visible how the structure splits and degrades as k grows.
cluster_k_sweep(
x,
k_range = 2:6,
linkage = "ward.D2",
embed = c("pca", "umap", "tsne"),
ncol = 3,
point_size = 2.2,
alpha = 0.9,
palette = "Dark 3",
base_size = 13
)
x |
A fitted result ( |
k_range |
Candidate cluster counts to display. |
linkage |
Agglomeration method used to cut the fused dissimilarity. |
embed |
Embedding for the (fixed) 2-D coordinates: |
ncol |
Columns in the panel grid. |
point_size |
Diameter of the plotted points (default |
alpha |
Point opacity (default |
palette |
Discrete |
base_size |
Base font size passed to the ggplot2 theme. |
The panels are drawn with ggplot2 for a clean, high-resolution result
whose quality is preserved when the figure is rescaled – save the returned
object to a vector device (PDF/SVG) or a high-DPI raster for publication, e.g.
ggplot2::ggsave("ksweep.pdf", cluster_k_sweep(fit), width = 9, height = 6).
Invisibly the ggplot object (also printed, so it draws on an open
device); the average silhouette per k is attached as the attribute
"silhouette".
cluster_selection_plot, embedding_plot
data(mosaic_toy)
fit <- M_ABC(mosaic_toy$List, numsim = 40, NC = 3)
cluster_k_sweep(fit, k_range = 2:6, point_size = 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.