Member-only story
Graphing mortality II
On bar graphs, showing a value using a line can be effective.
Last week, I looked at how to emulate the mortality graph with a ranged ribbon. This week, I seek to emulate a graph in the Office for National Statistics weekly death reports.

The graph has the following key elements:
- A stacked bar graph, showing deaths which involve and do not involve COVID-19. A death ‘involves’ a disease if clinicians believe it caused or contributed to the death.
- A straight line representing the weekly average of deaths in 2015 to 2019.
- A legend showing what all three counts correspond to on the graph.
- Informative text and arrows, highlighting public holidays influence death registrations in particular weeks.
Setting up
First, we start by install packages that we need:
library(tidyverse)
library(readxl)
library(scales)
library(lubridate)
I had some trouble installing the ‘ungeviz’ package in R Studio Cloud. I was able to find Prof Wilke’s code for the geom_hpline
function. We can use that instead. We draw the values from a prepared file (which I added a date to):
ons_deathregistration_figure3_df <- read_excel("ONS Weekly Death Registrations Figure 3 - 2021-04-14.xlsx",
sheet = "DATA",
col_types = c("numeric", "text", "date", "numeric", "numeric", "numeric"))
Next, we tidy that data set. Each of the three measures is its own row for each week:
ons_deathreg_tidy_df <- ons_deathregistration_figure3_df %>%
mutate(week_end_date = as_date(week_end_date)) %>%
pivot_longer(cols = 4:6,
names_to = "ons_measure",
values_to = "count")
Creating the graph
We set the date breaks to appear on the graph:
ons_week_breaks <- c("2020-01-03", "2020-03-13", "2020-05-22", "2020-07-31", "2020-10-09", "2020-12-18", "2021-04-02") %>%
as_date()
The code for the graph is then made up of several components. This is the core for the stacked bar…