Creates an alluvial-style diagram where each individual's trajectory is shown
as a separate line. This is an alias for plot_transitions() with
track_individuals = TRUE.
plot_trajectories(
x,
from_title = NULL,
title = NULL,
from_colors = NULL,
flow_color_by = "first",
node_width = 0.08,
node_border = NA,
node_spacing = 0.02,
label_size = 3.5,
label_position = c("beside", "inside", "above", "below", "outside"),
mid_label_position = NULL,
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,
line_alpha = 0.3,
line_width = 0.5,
jitter_amount = 0.8,
show_totals = FALSE,
total_size = 4,
total_color = "white",
total_fontface = "bold",
show_values = FALSE,
value_position = c("center", "origin", "destination"),
value_size = 3,
value_color = "black",
value_halo = NULL,
value_fontface = "bold",
value_nudge = 0.03,
value_min = 0,
value_digits = 2,
column_gap = 1,
proportional_nodes = TRUE,
node_label_format = NULL,
bundle_size = NULL,
bundle_legend = TRUE,
bundle_legend_size = 3,
bundle_legend_color = "grey50",
bundle_legend_fontface = "italic",
bundle_legend_position = c("bottom", "top")
)A ggplot2 object.
Data frame with one column per time point and one row per individual trajectory.
Column titles. Default NULL, which uses the
column names of x. Pass a character vector to override them.
Optional plot title. Applied via ggplot2::labs(title = title).
Colors for left-side nodes. Default uses palette.
Color trajectory lines by state. Supports
"source", "destination", "first", "last", or
NULL. Default "first".
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.
Position of labels for intermediate (middle)
columns in individual-tracking plots. Same options as
label_position. Default NULL uses label_position value.
Logical: add white halo around labels for readability? Default TRUE.
Color of state name labels. Default "black". Applied to multi-step and individual-tracking plots; simple two-column aggregate plots use black external labels and white inside labels.
Font face of state name labels ("plain", "bold", "italic", "bold.italic"). Default "plain". Applied to multi-step and individual-tracking plots; simple two-column aggregate plots use fixed label font faces.
Distance between node edge and label (in plot units). Default 0.02. Used by multi-step and individual-tracking plots.
Size of column titles. Default 5.
Color of column title text. Default "black". Applied to multi-step and individual-tracking plots; simple two-column aggregate plots use black titles.
Font face of column titles. Default "bold". Applied to multi-step and individual-tracking plots.
Controls bezier curve shape (0-1). Default 0.6.
Alpha for individual tracking lines. Default 0.3.
Width of individual tracking lines. Default 0.5.
Vertical jitter for individual lines (0-1). Default 0.8.
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: show transition counts on flows? Default FALSE.
Position of trajectory value labels: "center",
"origin", or "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). Applied to multi-step and
individual-tracking plots.
Font face of flow value labels. Default "bold". Applied to multi-step and individual-tracking plots.
Distance of value labels from node edge when using "origin" or "destination" positions. Default 0.03.
Minimum count to show a flow value label in multi-step and
individual-tracking plots. Default 0 (show all). Simple two-column
aggregate plots show all nonzero value labels when show_values = TRUE.
Number of decimal places for flow value labels and node totals. Default 2.
Horizontal spread of columns (0-1) for multi-step and individual-tracking plots. Default 1 uses full width. Use smaller values (e.g., 0.6) to bring columns closer together.
Logical: size nodes proportionally to counts in individual-tracking plots? Default TRUE.
Format string for node labels with {state} and
{count} placeholders in individual-tracking plots. Default NULL
(plain state name).
Example: "{state} (n={count})".
Controls line bundling for large datasets. Default NULL (no bundling). Integer >= 2: each drawn line represents that many cases. Numeric in (0,1): reduce to this fraction of original lines (e.g., 0.15 keeps about 15 percent of lines).
Logical or character: show annotation when bundling is
active? Default TRUE shows "Each line ~ N cases" below the plot.
Pass a string to use custom text (with {n} placeholder for count).
Size of the bundle legend text. Default 3.
Color of the bundle legend text. Default "grey50".
Font face of the bundle legend text. Default "italic".
Position of the bundle legend: "bottom" (default) or "top".
plot_transitions, plot_alluvial
df <- data.frame(
Baseline = c("Light", "Light", "Intense", "Resource"),
Week4 = c("Light", "Intense", "Intense", "Light"),
Week8 = c("Resource", "Intense", "Light", "Light"))
plot_trajectories(df, flow_color_by = "first")
Run the code above in your browser using DataLab