position-dodge
Dodge position adjustment: place grouped marks side by side.
Typically set on a layer as position: "dodge" rather than constructed directly; the constructor exists for symmetry with the other positions. When all marks at a given x share the same width, they split the bucket into equal slots and padding sets the gap between them. When widths differ (per-row width column), each mark uses its own width as its slot, with padding between slots and a shrink-to-fit if total slot use would exceed the bucket.
Every geom of a dodged group takes the same centre from width, so error bars, boxes, points and ranges line up with the columns of their group. The width of the geom itself sets only how wide its mark is in the slot. Under coord-radial the slots split the sweep of each category when theta is x, and the ring of each category when theta is y.
Usage
position-dodge(
width: 0.9,
padding: 0.1,
)Parameters
| Parameter | Default | Description |
|---|---|---|
width |
0.9 |
Total width reserved for the dodged group, as a fraction of the category width. |
padding |
0.1 |
Gap between adjacent dodge slots, in [0, 0.9]. With uniform widths it is a fraction of one slot; with mixed widths it is a fraction of the bucket. |
Returns
Position dictionary with name: "dodge", consumed by plot.
Examples
Bars dodged side by side per fill group within each x slot.
#let d = (
(q: "Q1", grp: "a", y: 3),
(q: "Q1", grp: "b", y: 5),
(q: "Q2", grp: "a", y: 4),
(q: "Q2", grp: "b", y: 2),
)
#plot(
data: d,
mapping: aes(x: "q", y: "y", fill: "grp", label: "y"),
layers: (
geom-col(position: "dodge"),
geom-label(position: "dodge", size: 14pt),
),
width: 10cm,
height: 6cm,
)Increase padding to widen the gap between dodged bars.
#let d = (
(q: "Q1", grp: "a", y: 3),
(q: "Q1", grp: "b", y: 5),
(q: "Q2", grp: "a", y: 4),
(q: "Q2", grp: "b", y: 2),
)
#plot(
data: d,
mapping: aes(x: "q", y: "y", fill: "grp"),
layers: (geom-col(position: position-dodge(padding: 0.3)),),
width: 10cm,
height: 6cm,
)See also
position-stack, position-fill, position-identity, position-jitter.