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,
flow_alpha = 0.5,
label_alpha = 0.3,
label_size = 8,
label_hjust = -0.05,
group_labels = NULL,
alpha = NULL,
...
)Arguments
- x
An
hv_sankeyobject.- flow_alpha
Transparency of the flow bands and the dashed column guides, \([0, 1]\). Default
0.5.- label_alpha
Transparency of the node-label fill, \([0, 1]\). Default
0.3(a light tint behind black text).- label_size
Font size for node labels in points. Default
8.- label_hjust
Horizontal justification offset for node labels. Default
-0.05.- group_labels
Optional named character vector mapping a
cluster_colsvalue to a milestone label. When supplied, that column's x-axis tick shows"<col>\n<label>"; unlisted columns show the bare column name. DefaultNULL(bare column names).- alpha
Deprecated. If supplied, sets both
flow_alphaandlabel_alpha(back-compatibility) and emits a message steering you to the two new arguments. DefaultNULL.- ...
Ignored; present for S3 consistency.
Value
A ggplot object using ggsankey geoms.
Compose with scale_fill_manual(), labs(), theme(),
and theme_hv_manuscript.
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") +
theme_hv_poster()
# Subset to K = 2 to 6
plot(hv_sankey(dta, cluster_cols = paste0("C", 2:6))) +
ggplot2::labs(x = NULL) +
theme_hv_poster()
}