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

Categorical scatter chart with x on the x-axis and y on the y-axis; at each x two coloured groups dodge into separate slots and points jitter within each slot.

Categorical scatter chart with x on the x-axis and y on the y-axis; at each x two coloured groups dodge into separate slots and points jitter within each slot.

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

Categorical scatter chart with x on the x-axis and y on the y-axis; three coloured groups per x form tight jittered clusters that stay inside their dodged slots.

Categorical scatter chart with x on the x-axis and y on the y-axis; three coloured groups per x form tight jittered clusters that stay inside their dodged slots.

See also

position-jitter, position-dodge.

Back to top