Powered by AppSignal & Oban Pro

Jittered and dodged positions: position_jitterdodge

notebooks/position_jitterdodge.livemd

Jittered and dodged positions: position_jitterdodge

Mix.install([
  {:giggly, path: Path.join(__DIR__, "..")},
  {:kino, "~> 0.19"}
  ])

About this notebook

This notebook follows the examples on ggplot2's reference page for position_jitterdodge(), in the order the page gives them. Each example shows ggplot2's code first and then Giggly's. An example Giggly cannot draw yet keeps its ggplot2 code and names what it is waiting for, so the page is also a list of what remains.

position_jitterdodge() dodges and jitters at once. It is mostly for lining points up with boxplots dodged side by side, as they are when a boxplot maps fill: each point moves to its group's place in the dodge, then by a little random noise, sideways only unless jitter.height says otherwise. Giggly dodges bars, and box plots by default with Giggly.Plot.geom_boxplot/3, but has none of this yet: no jitter, and no dodging of points.

Points over dodged boxplots

set.seed(596)
dsub <- diamonds[sample(nrow(diamonds), 1000), ]
ggplot(dsub, aes(x = cut, y = carat, fill = clarity)) +
  geom_boxplot(outlier.size = 0) +
  geom_point(pch = 21, position = position_jitterdodge())

R's sample() picks diamonds at random, the same ones every time after set.seed(596); pch = 21 is the point shape with both a border and a fill.

Not in Giggly yet: position_jitterdodge() with geom_point()'s position option.