Skip to content
svgbrushabledot-plot

Dot plot (Wilkinson)

What does a small sample look like, observation by observation?

Demo data · seed 20261101 · 72 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Count the dots: each one is one observation, stacked in its bin.
  2. Look at the stack heights for the shape, as you would on a histogram.
  3. Notice isolated dots: in a small sample each one matters.
  1. Callout 1: A tall stack: many observations share nearly the same value.
  2. Callout 2: An isolated dot: one observation far from the rest.

Watch out

  • Stacks shift a little with the bin width: read counts, not exact positions.

Defaults

Range ÷ binwidth
30
How many bins fit across the range: more bins give more detail and shorter stacks.
Range 5 to 80, step 1

Pinned in the code

  • Binning: Wilkinson dot-density (ggplot2 `geom_dotplot(method = "dotdensity")`): scan sorted values; a value ≥ the current bin end starts a bin [x, x + w).
  • Stack centre = midpoint of the first and last value in the bin; binwidth w = range / 30 by default.
  • Dot diameter = w in x units, shrunk if the tallest stack would not fit (stacks never overflow).
# Dot plot (Wilkinson) — Codesplash Chart Lab (recipe "dot-plot")
# controls: bins=30
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("dot-plot-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV

def dot_density(x, w):
    """Wilkinson dot-density binning (ggplot2 method = "dotdensity"): scan the sorted values;
    a value ≥ the current bin end starts a new bin [x, x + w). Returns (centre, count) per stack."""
    stacks, end = [], -np.inf
    for v in np.sort(x):
        if v >= end:
            stacks.append([])
            end = v + w
        stacks[-1].append(v)
    return [((s[0] + s[-1]) / 2, len(s)) for s in stacks]  # centre = midpoint of first and last value

x = df["sleep_h"].dropna().to_numpy(dtype=float)
w = (x.max() - x.min()) / 30  # binwidth = range / 30
stacks = dot_density(x, w)
tallest = max(count for _, count in stacks)

fig, ax = plt.subplots(figsize=(7, 4))
for centre, count in stacks:
    for j in range(count):  # dot diameter = binwidth in x units
        ax.add_patch(plt.Circle((centre, (j + 0.5) * w), 0.47 * w, color=PALETTE[0], linewidth=0))
ax.set_xlim(x.min() - w, x.max() + w)
ax.set_ylim(0, max(tallest * w, (x.max() - x.min()) / 4))
ax.set_aspect("equal")
ax.yaxis.set_visible(False)
ax.grid(axis="y", visible=False)
ax.set_xlabel("sleep_h")
plt.show()

Needs pandas, numpy, matplotlib · reads dot-plot-demo.csv · app theme from the optional codesplash helper