Visualising uncertainty

When and how to show uncertainty in charts

Dr Nicola Rennie

About me

Data visualisation specialist developing charts, standards, and training.


Background in statistics, operational research, data science consultancy, and academia.


Author of several R packages (mainly for visualisation).


Co-author of Royal Statistical Society’s Best Practices for Data Visualisation guidance.

Grid of R package hex logos

Welcome

  • 11:00 - 12:15: How and when to visualise uncertainty (Nicola Rennie)
    • When to visualise uncertainty
    • Principles of visualising uncertainty
    • Chart types for visualising uncertainty
    • Practical examples with R code
    • Exercise 1: create a chart using R
    • Exercise 2: discussion

nrennie.gitlab.io/dl4sg-uncertainty

Showing uncertainty in charts

Should you show uncertainty in a chart?

  • Sometimes seeing uncertainty is necessary to get an accurate understanding of the data and its limitations.
  • However, it can add complexity that makes charts harder to read and understand.
  • Not all chart types can show uncertainty easily.
  • Showing uncertainty does not make your work less trustworthy.

Ask yourself: Does seeing the uncertainty change the conclusion?

What’s the conclusion from this chart?

What’s the conclusion from this chart?

When not to show uncertainty in charts

You do not need to show uncertainty in charts if:

  • the uncertainty is consistently very small and it does not change the interpretation;
  • there is little or no overlap between ranges for values being compared;
  • there is some overlap between ranges but the overall trends are clear.

Types of charts

Types of uncertainty measures

  • Estimate + Range(s)
    • Probably the most common
    • e.g. mean and confidence intervals
  • Distribution
    • Show many (possible) values
    • e.g. all estimates from 1,000 simulations or different scenarios
  • Summary statistics
    • One number representing uncertainty
    • e.g. variance
    • Unlikely to be useful in a chart on its own

Estimate + Range(s)

You have point estimates for:

  • categories e.g. Group A vs Group B
  • discrete time points e.g. 2021 - 2023
  • continuous time points

And you want to show the range of uncertainty around those estimates.

Showing uncertainty in categorical data

Bad: bars with errorbars

Better: errorbars with point

Even better: Shaded areas with points

Comparing uncertainty within categories

Showing uncertainty over time

  • Show how uncertainty in estimate(s) changes, rather than implying a single precise value throughout.

  • Might need to show changes in main trend line e.g. observed vs forecast.

  • Might only show uncertainty ranges for part of a time period e.g. forecasts.

  • Might show different metrics of uncertainty in estimate and forecast.

Showing uncertainty over time

Uncertainty over discrete time periods

Uncertainty over continuous time

Uncertainty over continuous time

Uncertainty over continuous time

Caution: too many categories!

Consider small multiples instead

Legends

Legend with category labels next to a box with shaded area

Legends

Legend with category labels next to coloured shapes, and custom uncertainty legend

R code example

  • Uncertainty in categorical estimates with geom_rect()

OR

  • Uncertainty in continuous time estimates with geom_ribbon()

Your choice!

Exercise 1

  • Go to nrennie.gitlab.io/dl4sg-uncertainty/exercises/visualising-uncertainty.html . You’ll see some R code to load a dataset and create a line chart with three lines.
  • Inspect the data. You will see additional columns containing different levels of confidence intervals for different estimates in the data.
  • Decide if, and how, the uncertainty could be presented.
  • Edit the code to show uncertainty on the chart.
  • Hint: you may find geom_ribbon() in ggplot2 useful.

nrennie.gitlab.io/dl4sg-uncertainty

Showing distributions

Showing distributions of a single time point

Better: Beeswarms

Distributions over time

Trajectories over time

Trajectories over time

Elements of charts

Some elements of charts can imply uncertainty. For example:

  • dashed lines
  • transparency
  • lighter colours
  • chart type e/g. error bar

Be careful when using these elements if you’re not trying to communicate uncertainty.

Exercise 2

Here are two charts. What is good and bad about each of them? How would you visualise this data?

Resources

Slides: nrennie.gitlab.io/dl4sg-uncertainty