geom-errorbar

Errorbar layer: vertical range with a horizontal cap at each end.

Mapping must provide x, ymin, ymax. The width parameter sets the cap span in x data units for continuous x, and as a fraction of the per-category slot width for discrete x.

Usage

geom-errorbar(
  mapping: none,
  data: none,
  width: 0.4,
  stroke: 0.8pt,
  colour: auto,
  alpha: auto,
  linetype: "solid",
  stat: "identity",
  position: "identity",
  inherit-aes: true,
)

Parameters

Parameter Default Description
mapping none Layer-specific aesthetic mapping built with aes. Must map x, ymin, ymax.
data none Layer-specific dataset. Falls back to the plot data when none.
width 0.4 Cap span. A Typst length sets the cap span directly in panel units; a number is interpreted as x data units for continuous x and a fraction of the slot width for discrete x.
stroke 0.8pt Line thickness (a Typst length).
colour auto Fixed line colour. auto resolves via the colour scale.
alpha auto Line opacity in [0, 1].
linetype "solid" Dash keyword. Defaults to "solid".
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

Vertical error bars with default cap span.

#let d = range(1, 6).map(i => (
  x: i,
  lo: i - 0.5,
  hi: i + 0.5,
))
#plot(
  data: d,
  mapping: aes(x: "x", ymin: "lo", ymax: "hi"),
  layers: (geom-errorbar(width: 0.4),),
  width: 10cm,
  height: 6cm,
)

Vertical errorbars at x = 1 to 5 spanning lo to hi with horizontal caps at each end indicating uncertainty.

Vertical errorbars at x = 1 to 5 spanning lo to hi with horizontal caps at each end indicating uncertainty.

Combine with geom-point at the central estimate to convey the uncertainty around it.

#let d = range(1, 6).map(i => (
  x: i, y: i, lo: i - 0.5, hi: i + 0.5,
))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", ymin: "lo", ymax: "hi"),
  layers: (
    geom-errorbar(width: 0.3),
    geom-point(size: 3pt),
  ),
  width: 10cm,
  height: 6cm,
)

Vertical errorbars at x = 1 to 5 from lo to hi overlaid with circular markers at the central y estimate.

Vertical errorbars at x = 1 to 5 from lo to hi overlaid with circular markers at the central y estimate.

See also

geom-linerange, geom-pointrange, geom-crossbar.

Back to top