position-jitter
Random per-row offset on x and y.
Since 0.0.1.
width and height cap the absolute jitter in data units. The same seed always produces the same offsets, so the figure is stable across renders.
A discrete (categorical) axis is jittered directly across its level band. as-factor is only needed to force a numeric column onto a discrete axis.
Usage
position-jitter(
width: 0.4,
height: 0.4,
seed: 0,
)Parameters
| Parameter | Default | Description |
|---|---|---|
width |
0.4 |
Maximum absolute jitter applied to the x position. |
height |
0.4 |
Maximum absolute jitter applied to the y position. |
seed |
0 |
Integer seed for the deterministic pseudo-random offsets. |
Returns
Position dictionary with name: "jitter", consumed by plot.
Examples
Spread overplotted points with the default jitter amount.
#let d = ()
#for x in (1, 2, 3) {
for _ in range(0, 12) { d.push((x: x, y: 1)) }
}
#plot(
data: d,
mapping: aes(x: "x", y: "y"),
layers: (geom-jitter(size: 2pt),),
width: 10cm,
height: 6cm,
)Tighten width and zero height to keep jitter purely horizontal; bump seed to draw a different reproducible cloud.
#let d = ()
#for x in (1, 2, 3) {
for _ in range(0, 12) { d.push((x: x, y: 1)) }
}
#plot(
data: d,
mapping: aes(x: "x", y: "y"),
layers: (geom-point(
size: 2pt,
position: position-jitter(width: 0.15, height: 0, seed: 7),
),),
width: 10cm,
height: 6cm,
)