Skip to main content
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 on y, category on x — the default cartesian form draws vertical columns:

Stacked and grouped

Map a category to color, 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%
See position modes for the full list.

Horizontal bars

Keep the natural mapping — category on x, 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:

Styling the bars

geom.bar() accepts params to style the rectangle:
params.width
number
default:"0.7"
Bar width as a fraction of the band, in (0, 1].
params.borderRadius
number | 'auto' | 'full'
default:"auto"
Corner rounding in pixels, or 'full' for pill-shaped bars.
params.borderColor
string
Border color. The border is only drawn when this is set.
params.borderWidth
number
default:"1"
Border width in pixels; only applies when borderColor is set.