Skip to contents

Draws a cluster stability Sankey diagram using ggsankey geoms. Requires the ggsankey package. Install with:

remotes::install_github("davidsjoberg/ggsankey")

Usage

# S3 method for class 'hv_sankey'
plot(x, alpha = 0.8, label_size = 8, label_hjust = -0.05, ...)

Arguments

x

An hv_sankey object.

alpha

Transparency applied to flow bands and node labels. Default 0.8.

label_size

Font size for node labels in points. Default 8.

label_hjust

Horizontal justification offset for node labels. Default -0.05.

...

Ignored; present for S3 consistency.

Value

A ggplot object using ggsankey geoms. Compose with scale_fill_manual(), labs(), theme(), and hv_theme.

See also

Examples

dta <- sample_cluster_sankey_data(n = 300, seed = 42)

if (requireNamespace("ggsankey", quietly = TRUE)) {
  plot(hv_sankey(dta)) +
    ggplot2::labs(x = NULL, title = "Cluster Stability: K = 2 to 9") +
    hv_theme("poster")

  # Subset to K = 2 to 6
  plot(hv_sankey(dta, cluster_cols = paste0("C", 2:6))) +
    ggplot2::labs(x = NULL) +
    hv_theme("poster")
}