Creates an alluvial (Sankey) diagram showing aggregated flows between states.
This is an alias for plot_transitions() with aggregated flows (default).
plot_alluvial(
x,
from_title = "From",
to_title = "To",
title = NULL,
from_colors = NULL,
to_colors = NULL,
flow_fill = "#888888",
flow_alpha = 0.4,
flow_color_by = NULL,
flow_border = NA,
flow_border_width = 0.5,
node_width = 0.08,
node_border = NA,
node_spacing = 0.02,
label_size = 3.5,
label_position = c("beside", "inside", "above", "below", "outside"),
label_halo = TRUE,
label_color = "black",
label_fontface = "plain",
label_nudge = 0.02,
title_size = 5,
title_color = "black",
title_fontface = "bold",
curve_strength = 0.6,
show_values = FALSE,
value_position = c("center", "origin", "destination", "outside_origin",
"outside_destination"),
value_size = 3,
value_color = "black",
value_halo = NULL,
value_fontface = "bold",
value_nudge = 0.03,
value_min = 0,
show_totals = FALSE,
total_size = 4,
total_color = "white",
total_fontface = "bold",
conserve_flow = TRUE,
min_flow = 0,
threshold = 0,
value_digits = 2,
column_gap = 1
)A ggplot2 object.
Input data in one of several formats:
A transition matrix (rows = from, cols = to, values = counts)
Two vectors: pass before as x and after as second argument
(contingency table computed automatically, like chi-square)
A 2-column data frame (raw observations; table computed automatically)
A data frame with columns: from, to, count
A list of matrices for multi-step transitions
Title for the left column. Default "From". For multi-step, use a vector of titles (e.g., c("T1", "T2", "T3", "T4")).
Title for the right column. Default "To". Ignored for multi-step.
Optional plot title. Applied via ggplot2::labs(title = title).
Colors for left-side nodes. Default uses palette.
Colors for right-side nodes. Default uses palette.
Fill color for flows. Default "#888888" (grey). Ignored if flow_color_by is set.
Alpha transparency for flows. Default 0.4.
Color flows by "source", "destination", or NULL (use flow_fill). Default NULL.
Border color for flows. Default NA (no border).
Line width for flow borders. Default 0.5.
Width of node rectangles (0-1 scale). Default 0.08.
Border color for nodes. Default NA (no border).
Vertical spacing between nodes (0-1 scale). Default 0.02.
Size of node labels. Default 3.5.
Position of node labels: "beside" (default), "inside", "above", "below", "outside".
Applied to first and last columns. See mid_label_position for middle columns.
Logical: add white halo around labels for readability? Default TRUE.
Color of state name labels. Default "black".
Font face of state name labels ("plain", "bold", "italic", "bold.italic"). Default "plain".
Distance between node edge and label (in plot units). Default 0.02. Increase for more spacing.
Size of column titles. Default 5.
Color of column title text. Default "black".
Font face of column titles. Default "bold".
Controls bezier curve shape (0-1). Default 0.6.
Logical: show transition counts on flows? Default FALSE.
Position of flow values: "center", "origin", "destination", "outside_origin", "outside_destination". Default "center".
Size of value labels on flows. Default 3.
Color of value labels. Default "black".
Logical: add halo around flow value labels? Default NULL
(inherits from label_halo).
Font face of flow value labels. Default "bold".
Distance of value labels from node edge when using "origin" or "destination" positions. Default 0.03.
Minimum count to show a flow value label. Default 0 (show all).
Use to hide small flows (e.g., value_min = 100).
Logical: show total counts on nodes? Default FALSE.
Size of total labels. Default 4.
Color of total labels. Default "white".
Font face of total labels. Default "bold".
Logical: should left and right totals match? Default TRUE. When FALSE, each side scales independently (allows for "lost" or "gained" items).
Minimum flow value to display. Default 0 (show all).
Minimum edge weight to display. Flows below this value are
removed. Combined with min_flow: effective minimum is
max(threshold, min_flow). Default 0.
Number of decimal places for flow value labels and node totals. Default 2.
Horizontal spread of columns (0-1). Default 1 uses full width. Use smaller values (e.g., 0.6) to bring columns closer together.
plot_transitions, plot_trajectories
if (FALSE) {
# From a transition matrix
mat <- matrix(c(50, 10, 5, 15, 40, 10), 2, 3)
rownames(mat) <- c("A", "B")
colnames(mat) <- c("X", "Y", "Z")
plot_alluvial(mat)
}
Run the code above in your browser using DataLab