position-jitter

Random per-row offset on x and y.

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.

Only continuous (numeric) columns are jittered: a discrete x is left alone. Users wanting jitter over a discrete axis should map the column via as-numeric first.

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,
)

Scatter chart with x on the x-axis and y on the y-axis; three clouds of points spread around x = 1, 2, 3 with random horizontal and vertical offsets revealing overplotting.

Scatter chart with x on the x-axis and y on the y-axis; three clouds of points spread around x = 1, 2, 3 with random horizontal and vertical offsets revealing overplotting.

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,
)

Scatter chart with x on the x-axis and y on the y-axis; three narrow horizontal strips of points at y = 1 spread only along x with a tight jitter width.

Scatter chart with x on the x-axis and y on the y-axis; three narrow horizontal strips of points at y = 1 spread only along x with a tight jitter width.

See also

position-nudge, geom-jitter.

Back to top