geom-col

Bar layer with heights taken from the y aesthetic.

Each row becomes one bar centred at its x value. Use geom-bar (stat-count) when you want automatic counting; geom-col expects pre-aggregated y.

Usage

geom-col(
  mapping: none,
  data: none,
  width: 0.9,
  colour: auto,
  fill: auto,
  stroke: none,
  alpha: auto,
  key: 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.
width 0.9 Bar width as a fraction of the category width (0 to 1).
colour auto Bar outline colour. auto resolves via the colour scale, falling back to the theme ink only when neither colour nor fill is set.
fill auto Bar fill colour. auto resolves via the fill scale or a neutral default.
stroke none Bar outline thickness (a Typst length) or stroke dictionary; none disables the outline.
alpha auto Bar opacity in [0, 1].
key auto Legend glyph override built with a draw-key-* helper. auto picks the default for the geom.
stat "identity" Statistical transform name. Usually "identity".
position "identity" Position adjustment: "identity", "stack", "dodge", or "fill".
inherit-aes true Whether to merge the plot-level mapping into this layer’s mapping.

Returns

Layer dictionary consumed by plot.

Examples

Pre-aggregated heights drawn one bar per row.

#let d = (
  (q: "Q1", revenue: 10),
  (q: "Q2", revenue: 18),
  (q: "Q3", revenue: 25),
  (q: "Q4", revenue: 22),
)
#plot(
  data: d,
  mapping: aes(x: "q", y: "revenue"),
  layers: (geom-col(),),
  width: 10cm,
  height: 6cm,
)

Bar chart of revenue by quarter (Q1 through Q4) on the x axis with heights taken directly from the y aesthetic.

Bar chart of revenue by quarter (Q1 through Q4) on the x axis with heights taken directly from the y aesthetic.

Adding a fill mapping with position: "stack" (default for stacked) accumulates contributions per category.

#let d = (
  (q: "Q1", revenue: 6, region: "EU"),
  (q: "Q1", revenue: 4, region: "US"),
  (q: "Q2", revenue: 9, region: "EU"),
  (q: "Q2", revenue: 9, region: "US"),
  (q: "Q3", revenue: 14, region: "EU"),
  (q: "Q3", revenue: 11, region: "US"),
)
#plot(
  data: d,
  mapping: aes(x: "q", y: "revenue", fill: "region"),
  layers: (geom-col(position: "stack"),),
  width: 10cm,
  height: 6cm,
)

Stacked bar chart of revenue per quarter with EU and US regions accumulated by fill aesthetic in each bar.

Stacked bar chart of revenue per quarter with EU and US regions accumulated by fill aesthetic in each bar.

See also

geom-bar, position-stack, position-dodge, position-fill.

Back to top