geom-crossbar

Crossbar layer: a box from ymin to ymax with a horizontal bar at y.

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

Usage

geom-crossbar(
  mapping: none,
  data: none,
  width: 0.6,
  colour: auto,
  fill: auto,
  stroke: 0.6pt,
  middle-stroke: 1.2pt,
  alpha: auto,
  stat: "identity",
  position: "identity",
  inherit-aes: true,
)

Parameters

Parameter Default Description
mapping none Layer-specific aesthetic mapping built with aes. Must map x, y, ymin, ymax.
data none Layer-specific dataset. Falls back to the plot data when none.
width 0.6 Box width. In x data units for continuous x; a fraction of the slot width for discrete x.
colour auto Stroke colour for the box and the median bar. auto falls back to the theme ink only when neither colour nor fill is set.
fill auto Box fill colour. auto resolves via the fill scale or a neutral default.
stroke 0.6pt Stroke thickness for the box outline.
middle-stroke 1.2pt Stroke thickness for the median bar.
alpha auto Box opacity in [0, 1].
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

Box from lo to hi with the median bar at y.

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

Crossbars at x = 1 to 4 with hollow boxes spanning lo to hi and a thick median bar at y for each row.

Crossbars at x = 1 to 4 with hollow boxes spanning lo to hi and a thick median bar at y for each row.

Map fill to a categorical column to colour the box per group.

#let d = range(1, 5).map(i => (
  x: i, y: i, lo: i - 0.6, hi: i + 0.6,
  k: if calc.rem(i, 2) == 0 { "even" } else { "odd" },
))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", ymin: "lo", ymax: "hi", fill: "k"),
  layers: (geom-crossbar(alpha: 0.6),),
  width: 10cm,
  height: 6cm,
)

Crossbars across x = 1 to 4 with boxes coloured by even/odd category via the fill aesthetic.

Crossbars across x = 1 to 4 with boxes coloured by even/odd category via the fill aesthetic.

See also

geom-errorbar, geom-pointrange, geom-boxplot.

Back to top