geom-step

Step layer connecting observations as a stair-step path, one per group.

direction chooses between "hv" (horizontal first, then vertical) and "vh" (vertical first, then horizontal).

Usage

geom-step(
  mapping: none,
  data: none,
  direction: "hv",
  stroke: 0.8pt,
  colour: auto,
  alpha: auto,
  linetype: auto,
  stat: "identity",
  position: "identity",
  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. Falls back to the plot data when none.
direction "hv" Step direction: "hv" (default) or "vh".
stroke 0.8pt Line thickness (a Typst length).
colour auto Fixed line colour. auto resolves via the colour scale or a neutral default.
alpha auto Line opacity in [0, 1].
linetype auto Dash keyword (e.g., "solid", "dashed"). auto honours the linetype scale.
stat "identity" Statistical transform name. Usually "identity".
position "identity" Position adjustment name. Usually "identity".
inherit-aes true Whether to merge the plot-level mapping into this layer’s mapping.

Returns

Layer dictionary consumed by plot.

Examples

Default "hv" step path moving right then up between points.

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

Stair-step polyline of y against x = 0 to 6 moving horizontally then vertically between successive points.

Stair-step polyline of y against x = 0 to 6 moving horizontally then vertically between successive points.

"vh" direction reverses the corner placement, useful when the change is best read as happening at the previous timestamp.

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

Stair-step polyline of y against x = 0 to 6 moving vertically then horizontally between successive points.

Stair-step polyline of y against x = 0 to 6 moving vertically then horizontally between successive points.

See also

geom-line, geom-path.

Back to top