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, the result matches a simple uniform dodge. 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.
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 mixed-width mode, as 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"),
layers: (geom-col(position: "dodge"),),
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.