geom-area

Area layer: filled polygon from y = 0 up to y along x, per group.

Mapping must provide x and y. Discrete colour, fill, or group mappings split rows into separate filled polygons drawn back to front.

(default) draws a smooth polygon; "hv" (horizontal then vertical) or "vh" (vertical then horizontal) step the top edge like geom-step.

resamples all groups onto a shared x-grid before stacking so bands join cleanly even when groups carry different x values. Pass "identity" to skip alignment.

Usage

geom-area(
  mapping: none,
  data: none,
  colour: auto,
  fill: auto,
  stroke: none,
  alpha: auto,
  direction: none,
  stat: "align",
  position: "stack",
  inherit-aes: true,
)

Parameters

Parameter Default Description
mapping none Layer-specific aesthetic mapping built with aes. Falls back to the plot mapping when none.
data none Layer-specific dataset, or a function applied to the plot data returning the layer frame. Falls back to the plot data when none.
colour auto Fixed outline colour. auto resolves via the colour scale, falling back to the theme ink only when neither colour nor fill is set.
fill auto Fixed fill colour. auto resolves via the fill scale, the colour scale, or a neutral default.
stroke none Outline thickness (a Typst length) or stroke dictionary; none disables the outline.
alpha auto Fill opacity in [0, 1].
direction none Step interpolation for the filled top edge. none
stat "align" Statistical transform name. Defaults to "align", which
position "stack" Position adjustment name. Defaults to "stack".
inherit-aes true Whether to merge the plot-level mapping into this layer’s mapping.

Returns

Layer dictionary consumed by plot.

Examples

Single filled area between y = 0 and a smooth curve.

#let d = range(0, 12).map(i => (x: i, y: calc.sin(i * 0.6) + 1.5))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-area(alpha: 0.4),),
  width: 10cm,
  height: 6cm,
)

Filled area chart with x (0 to 11) on the horizontal axis and a sine wave shifted upward filled down to y = 0.

Filled area chart with x (0 to 11) on the horizontal axis and a sine wave shifted upward filled down to y = 0.

Map fill to a discrete column; groups stack automatically.

#let d = ()
#for grp in ("a", "b") {
  for i in range(0, 12) {
    d.push((x: i, y: 1.5 + calc.sin(i * 0.5) + (if grp == "b" { 1 } else { 0 }), grp: grp))
  }
}
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", fill: "grp"),
  layers: (geom-area(alpha: 0.6),),
  width: 10cm,
  height: 6cm,
)

Stacked area chart over x with two groups (a, b) coloured by fill aesthetic and stacked vertically.

Stacked area chart over x with two groups (a, b) coloured by fill aesthetic and stacked vertically.

Step the top edge with direction: "hv" for a histogram-like filled area.

#let d = range(0, 7).map(i => (x: i, y: calc.rem(i * 3, 5) + 1))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-area(direction: "hv", alpha: 0.4),),
  width: 10cm,
  height: 6cm,
)

Stepped filled area chart over x = 0 to 6 whose top edge holds each level flat then jumps to the next, filled down to y = 0.

Stepped filled area chart over x = 0 to 6 whose top edge holds each level flat then jumps to the next, filled down to y = 0.

See also

geom-ribbon, geom-line.

Back to top