geom.bar() draws a rectangle per observation. In the default cartesian plane it produces vertical columns; add coord.flip() to lay them on their side as horizontal bars. One geom, two orientations. Columns suit comparing categories or a value over discrete time periods; bars suit ranking and categories with long labels that wouldn’t fit under a vertical axis.
Basic example
Value ony, category on x — the default cartesian form draws vertical columns:
Stacked and grouped
Map a category tocolor, then choose how the bars in each band arrange with position. In long format, one row per quarter × region:
'stack'— segments stacked into one column'dodge'— segments side by side within the band'fill'— stacked and normalised to 100%
'dodge', so a multi-series bar chart with no position renders grouped. See position modes for the full list.
Negative values
'identity' draws each bar at its raw value, so bars with a negative y hang below the zero baseline instead of being folded into a stack:
Counting rows
Map onlyx and set the count stat to get a bar per category whose height is the number of rows in it — no value column needed:
Horizontal bars
Keep the natural mapping — category onx, value on y — and add coord.flip() to swap the axes. Stacking, grouping and styling all carry over unchanged; only the orientation differs:
Ranking
To order bars by value, sort the data with a transform — most useful with horizontal bars:Bar geometry
geom.bar() takes one param, and it is geometry rather than paint — it sets the band envelope the compiler writes into the position variables:
number
default:"0.7"
Bar width as a fraction of the band the discrete scale allocates to the
category, in
(0, 1].(0, 1] draws with a substitute width and reports an INVALID_GEOM_PARAM warning.
Painting the bars
Fill, opacity, corner rounding and the border come from the stylesheet, through thestyle.geom.bar target:
style.geom.bar declares color, alpha, saturation, borderRadius, borderColor and borderWidth.
Corner rounding
borderRadius is a named token rather than a pixel value, so each coordinate system renders it in its own frame — a rectangle in cartesian, an arc corner in polar:
Borders
borderWidth is 1 by default; the border becomes visible once borderColor resolves to a color. A border in the chart’s background color is the usual way to separate stacked segments or pie wedges:
{ layer } to paint one bar layer of a combo differently, or with { where } to paint by value — negative bars in a warning color, for instance.
Related
- Styling — the stylesheet, its cascade and every target
- Coordinate systems — how
coord.flip()works - Geoms & layers — position modes and layering
- Scales — control the value axis range

