stat-align

Align statistic: resample each group onto a shared x-grid.

Builds the union of every group’s x values plus zero-crossings within each group, deduped and sorted. Each group’s y is linearly interpolated onto that grid; rows outside a group’s input range are dropped, and the trimmed extremes are padded with y = 0 so stacked areas join cleanly between groups.

Usage

stat-align()

Returns

Statistic object with name: "align", consumed by geom layers.

Outputs

  • x.
  • y.

Examples

Two groups with mismatched x sampled onto a stacked area.

#let d = (
  (x: 0, y: 1, k: "a"), (x: 2, y: 3, k: "a"), (x: 4, y: 2, k: "a"),
  (x: 1, y: 2, k: "b"), (x: 3, y: 1, k: "b"), (x: 5, y: 4, k: "b"),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", fill: "k"),
  layers: (geom-area(stat: stat-align(), position: "stack"),),
  width: 12cm,
  height: 6cm,
)

Stacked area chart with x and y axes, two groups a and b aligned onto a shared x-grid so their areas stack without gaps.

Stacked area chart with x and y axes, two groups a and b aligned onto a shared x-grid so their areas stack without gaps.

See also

geom-area, geom-ribbon, stat-identity.

Back to top