position-jitterdodge
Combined dodge then jitter position adjustment.
Applies dodge to spread groups across each x bucket, then jitters within each dodged slot so overlapping points become visible. The same seed always produces the same offsets so renders are reproducible.
Usage
position-jitterdodge(
width: 0.4,
height: 0,
dodge-width: 0.75,
seed: 0,
)Parameters
| Parameter | Default | Description |
|---|---|---|
width |
0.4 |
Maximum absolute jitter applied to the (already dodged) x position, in data units. |
height |
0 |
Maximum absolute jitter applied to the y position, in data units. |
dodge-width |
0.75 |
Total width reserved for the dodged group, as a fraction of the category width. |
seed |
0 |
Integer seed for the deterministic pseudo-random offsets. |
Returns
Position dictionary with name: "jitterdodge", consumed by plot.
Examples
Dodge by colour then jitter within each slot, useful for dense categorical scatters.
#let d = ()
#for x in (1, 2, 3) {
for grp in ("a", "b") {
for _ in range(0, 8) { d.push((x: x, y: 1, grp: grp)) }
}
}
#plot(
data: d,
mapping: aes(x: "x", y: "y", colour: "grp"),
layers: (
geom-jitter(size: 2pt, position: position-jitterdodge()),
),
width: 10cm,
height: 6cm,
)Tune dodge-width and width to keep jittered clusters inside their dodged slots.
#let d = ()
#for x in (1, 2, 3) {
for grp in ("a", "b", "c") {
for _ in range(0, 8) { d.push((x: x, y: 1, grp: grp)) }
}
}
#plot(
data: d,
mapping: aes(x: "x", y: "y", colour: "grp"),
layers: (geom-jitter(
size: 2pt,
position: position-jitterdodge(dodge-width: 0.9, width: 0.15),
),),
width: 10cm,
height: 6cm,
)