4  Distributions: histograms, box plots, points, error bars

Figures comparing the distribution of values across groups are the most common type in clinical research. Depending on how you draw them, what is shown and what is hidden changes a lot.

4.1 Histograms: the shape changes with the bin width

With a bin width of 5 mm you can see two peaks (Adelie/Chinstrap, and Gentoo), but at 15 mm it looks like a single peak. Check histograms by trying several bin widths.

4.2 What does a box plot show?

The parts of a box plot are the following values.

  • The line inside the box: the median
  • Top and bottom of the box: the first quartile (25%) and the third quartile (75%). The height of the box is the interquartile range (IQR)
  • Whiskers: from the edge of the box to the most extreme data point within 1.5 × IQR
  • Points: data beyond the whiskers (candidate outliers)

Let’s compute them by hand and compare with the figure.

NoteHow quartiles are computed

There are many ways to compute quartiles. R’s quantile() default (type 7) and the default of pandas / NumPy (linear interpolation) are the same method, so the box plots from the two agree. SPSS and some Excel functions may use other methods, and with small samples the values differ.

4.3 What box plots hide

Let’s create a distribution with two peaks and a distribution with one peak that have similar quartiles.

In the box plots the two groups look very similar, but the violin plots and points show that the right-hand group has almost no values in the middle. With up to a few dozen observations, showing every point is the most honest option.

4.4 Overlaying points on a box plot

A commonly used form is a box plot with points overlaid. If you forget to remove the box plot’s outlier points, outliers are drawn twice.

TipJitter is random

The amount by which points are shifted sideways is random, so the figure changes slightly every time you run it. For figures in papers, make them reproducible with position_jitter(seed = ) in R, or by setting np.random.seed() before running in seaborn.

4.4.1 Splitting by two categories

If you also split by sex, you need to align the horizontal positions of boxes and points (dodge).

4.5 Means and error bars: SD, SE, 95% confidence interval

Figures showing the mean as a point with error bars are also common. What the error bars represent changes the meaning completely.

Error bar What it represents As n increases
SD (standard deviation) Spread of the individual values Does not change
SE (standard error = SD / √n) Uncertainty in the estimate of the mean Gets smaller
95% confidence interval (≈ mean ± 1.96 SE) Range where the mean is likely to be Gets smaller

With the same data, SE and CI error bars are much shorter than SD, and the group differences look larger. Always state what the error bars are in the figure’s description (legend, caption).

Warningseaborn’s default error bar is a “bootstrap 95% CI”

If you specify nothing, seaborn’s pointplot(), barplot() and lineplot() draw a 95% confidence interval computed by bootstrapping (random numbers). It changes slightly every run and also differs slightly from a t-distribution CI. Write errorbar=("ci", 95) explicitly and specify seed=, or use errorbar="se" or errorbar="sd", and state what you drew.

WarningAvoid bar chart + error bar (dynamite plots)

Showing the mean as a bar height with an error bar on top hides the shape of the distribution, the sample size and the outliers, so many journals recommend avoiding it. Use points, or box plots + points.

ImportantChapter summary
  • For histograms, try several bin widths
  • Box plots show median, quartiles, 1.5 × IQR whiskers and outliers, and they hide two-peaked distributions
  • When overlaying points, remove the box’s outliers and fix the random seed for the jitter
  • Always state whether error bars are SD, SE or CI. seaborn’s default is a bootstrap CI