5  Significance asterisks and brackets

Figures comparing groups with test results drawn in as brackets and asterisks (*) are very common in life-science and medical papers. In this chapter, you will practise running the tests yourself and drawing the results yourself. There are convenient packages, but being able to control what you draw is what matters.

5.1 Procedure

  1. Decide what to compare with what (all pairs, or only against a control group)
  2. Run the tests and apply a multiple-comparison correction
  3. Convert p-values to symbols such as asterisks
  4. Draw the brackets and symbols at heights that don’t overlap the data

5.2 1–2. Tests and multiple-comparison correction

We compare the body mass of the 3 species two at a time (3 comparisons). So that the brackets can later be stacked without overlapping, we order comparisons of neighbours (short brackets) first and comparisons of distant groups (long brackets) last. Here we run t-tests that do not assume equal variances (Welch) and correct with Holm’s method.

The difference between Adelie and Chinstrap is 27 g with p = 0.65 (still 0.65 after correction); the differences between Gentoo and the other 2 species are about 1360–1390 g, with very small p-values.

5.3 3. Turning p-values into symbols

The following mapping is common, but it differs between journals and fields, so always state it in the figure’s description.

p-value Symbol
p ≥ 0.05 ns (not significant)
p < 0.05 *
p < 0.01 **
p < 0.001 ***
p < 0.0001 ****

5.4 4. Drawing the brackets and symbols

5.4.1 Knowing the “positions” on a categorical axis

To draw a bracket, you need each group’s position on the horizontal axis (a number).

  • ggplot2: positions on a categorical axis are 1, 2, 3, … (in the order of the factor levels)
  • seaborn: positions on a categorical axis are 0, 1, 2, …

Set the height a little above the maximum of the data of the two groups being compared, and shift each bracket up one step so they don’t overlap.

TipThe order of stacking brackets

If you put the long bracket (Adelie–Gentoo) at the bottom, the symbol above it collides with the short brackets. The basic rule is to stack short brackets at the bottom and long ones on top. If a symbol is too close to the bracket above, widen the bracket spacing (step).

TipPositions based on “data values” work for any figure

Because the bracket heights are computed from the data maximum and range, the same code works even if you change the variable (flipper length, bill depth). If you compute ymax and step from each group’s maximum, you can also keep the brackets more compact.

5.4.2 Wrapping it in a function

Since we use this repeatedly, we make functions that build the figure from “the data, the group column, the value column, and the table of comparisons”.

5.5 When each group is split in two (dodge)

In a figure comparing males and females within each species, the boxes are shifted sideways, so the brackets also need to be at the shifted positions.

  • ggplot2: with position_dodge(width = 0.75) and 2 groups, ± 0.75 / 4 = ± 0.1875 from the centre
  • seaborn: with 2 groups via hue (default width 0.8), ± 0.2 from the centre
NoteDo these 3 comparisons need a correction?

The 3 tests “comparing males and females within each species” are sometimes regarded as separate questions and left uncorrected, and sometimes corrected together. State which you did in the figure’s description.

5.6 Using a package: ggsignif

R’s ggsignif draws brackets and asterisks for you with geom_signif().

WarningIf you leave the tests to the package, there is no correction

geom_signif(test = ...) tests each comparison independently and applies no multiple-comparison correction. The kind of t-test (Welch or not) is also left to the defaults. The safe approach is to run the tests yourself and pass only the results via annotations = (symbols), y_position = (heights) and xmin =, xmax = (positions).

In Python, the statannotations package plays the same role, but it often doesn’t work with seaborn 0.13, so this hands-on recommends drawing them yourself as with bracket() above.

5.7 What to think about before adding asterisks

WarningAsterisks throw away a lot of information
  • Asterisks only convey “which threshold the p-value is below”. The size, direction and confidence interval of the difference are unknown
  • “ns” does not mean “no difference” (Chi-square test hands-on, Chapter 8)
  • Drawing brackets for many pairs makes the figure unreadable and makes the multiple-comparison problem bigger. Decide the pairs to compare in advance
  • In the figure’s description, state the name of the test, the correction method, the symbol mapping and the sample size of each group
  • If possible, show the p-value itself (p = 0.003) or the difference and its 95% confidence interval instead of asterisks
ImportantChapter summary
  • Run the tests and corrections yourself, and draw brackets and symbols from the results table
  • Category positions are 1, 2, 3 in ggplot2 and 0, 1, 2 in seaborn. When dodged, ±(width / 4) or ±0.2 from the centre
  • Compute bracket heights from the data maximum and range, shift each one up a step, and make room at the top
  • If you leave the tests to ggsignif, there is no correction. Pass symbols and positions instead
  • p-values, or differences with confidence intervals, carry more information than asterisks. Always state the test, the correction and what the symbols mean