position-stack
Stack position adjustment: cumulate y per x bucket.
Stacking is per x bucket across all groups, so different groups at the same x are stacked on top of each other in row order.
Typically set on a layer as position: "stack" rather than constructed directly; the constructor exists for symmetry with the other positions.
Usage
position-stack()Returns
Position dictionary with name: "stack", consumed by plot.
Examples
Two groups stacked per quarter to show component contribution to a total.
#let d = (
(q: "Q1", grp: "a", y: 3),
(q: "Q1", grp: "b", y: 5),
(q: "Q2", grp: "a", y: 4),
(q: "Q2", grp: "b", y: 2),
(q: "Q3", grp: "a", y: 6),
(q: "Q3", grp: "b", y: 4),
)
#plot(
data: d,
mapping: aes(x: "q", y: "y", fill: "grp"),
layers: (geom-col(position: "stack"),),
width: 10cm,
height: 6cm,
)Stacked area chart over time, useful when the running total itself is informative.
#let d = ()
#for grp in ("a", "b", "c") {
for i in range(0, 10) {
d.push((x: i, y: i * 0.3 + (if grp == "b" { 1 } else if grp == "c" { 2 } else { 0 }), grp: grp))
}
}
#plot(
data: d,
mapping: aes(x: "x", y: "y", fill: "grp"),
layers: (geom-area(position: "stack", alpha: 0.6),),
width: 10cm,
height: 6cm,
)