Shows how quantities move between stages. Nodes are drawn as bars at each stage and flows as curved ribbons whose thickness is the value.

geom_sankey(
  mapping = NULL,
  data = NULL,
  alpha = NULL,
  node_width = NULL,
  label = TRUE
)

geom_alluvial(
  mapping = NULL,
  data = NULL,
  alpha = NULL,
  node_width = NULL,
  label = TRUE
)

Arguments

mapping, data

Standard layer overrides. Requires x (source node), xend (target node), and y (flow value).

alpha

Ribbon opacity.

node_width

Node bar width as a fraction of the panel.

label

Draw node labels.

Value

A Layer to add with +.

Details

The layout (node positions, ribbon paths) is computed from scratch: nodes are stacked within their stage in decreasing size, and ribbons leave and enter nodes in the same order, which is what keeps the crossings readable.

Examples

d <- data.frame(
  from = c("Visited", "Visited", "Signed up", "Signed up"),
  to = c("Signed up", "Left", "Purchased", "Churned"),
  n = c(400, 600, 150, 250)
)
ggnext(d, aes(x = from, xend = to, y = n)) +
  geom_sankey() +
  theme_void()
#> <ggnext plot>
#>   data:  4 x 3
#>   aes:   x = from, xend = to, y = n
#>   layers: 1 
#>   coord: cartesian
#>   mode:  static