The Bar Chart Race-Version 2

As stated in my previous post on the bar chart race graphic I made, I wanted to make a few different versions to address some of the criticisms of the original. This is version #2, or #1 of the alternatives.

Except I’m tweaking it a bit. I want to show all the top global causes of death, not just summarize them as one bar. It won’t make for quite as eye-popping a visualization, but it will be more complete. I will also adjust for seasonality of global deaths, since some comparative causes, like influenza, definitely have a higher rate of death earlier in the year.

Summarizing the Causes

For the causes, I will use Our World in Data because they have the most easily accessible dataset, which they’ve already summarized from the Global Burden of Disease study, my original source.

I clicked on the link to download the image on the right. From there it prompts you to click on a link to download a CSV file with all of the data used in the graph. That saves in my Download file as a CSV file called annual-number-of-deaths-by-cause.csv

#prior to this load libraries; dplyr,tidyr,matrixStats,lubridate
df<-read.csv("~/Downloads/annual-number-of-deaths-by-cause.csv",stringsAsFactors = F)

#limit only to World, not individual countries
#select only year and causes of death
#change column headers to something simpler
#malnutrition and nutritional are similar causes; add them and get rid of one

How did I handle influenza? It had to be calculated separately. For that I used a paper from the Lancet published by the Global Burden of Disease study group, in which they aim to estimate the global mortality burden specifically from influenza. In it they give an estimate of 145,000 global deaths from influenza in 2017, with a 95% uncertainty interval of 99,000-200,000. As that is an uneven uncertainty interval, for the sake of simulation I’ll say the estimate is 145,000 and give the higher band of uncertainty of 55,000, which would give a standard deviation of 55000/1.96=28061.22.


We also need to normalize the data to 2020 population. For that I used Worldometer’s population estimates. I find web tables easier to manipulate in Google Sheets using the importhtml function. So that is what I did. From there I calculated a population multiplier for each year from 1990 to 2017 compared to 2020.

#convert all columns except influenza to 2020 population
for (i in 2:33){
#influenza is all in 2017 numbers, so only need to apply 2017 multiplier to it
#now need to remove influenza figures from lower respiratory infectious disease figures, since influenza was included in those numbers in the original study

In a previous version of this, I calculated the average and standard deviation for each disease for 1990-2017. However, I noticed on further inspection that many of these diseases have declined consistently in prevalence over time. Using an average of almost 30 years led to many of the diseases having much higher figures than they had in say, the last five years of data. So, for a more fair comparison, I decided to run a trend analysis on the data to project forward to 2020 what the mortality is most likely to be.

#first need to impute years with missing data; there aren't many, but it makes the data more complete
for (i in 2:34){

Seasonality of Mortality

This was a bit more difficult to determine. For it I used the UN Data database of deaths by month of death. It was difficult though because the deaths were listed individually for every country in the world and each one had different numbers of years and months per year where data was available. So I had to pull all of the data and then narrow it down just to countries for which full year data was available. I found a group of countries for which multiple years of data were available with all 12 months available in each year.

Given China’s inconsistent data reporting, it is not included in the database. But beyond that problem, this should given a reasonable idea of the seasonality of mortality globally, especially as it includes countries at multiple different latitudes (some respiratory diseases are thought to have more of a seasonal component in colder climes).

From that I was able to calculate the average seasonal factor for each month. They are as follows:

Month Seasonal Multiplier
January 1.166
February 1.022
March 1.084
April 0.969
May 0.979
June 0.924
July 0.971
August 0.962
September 0.915
October 0.986
November 0.973
December 1.048

Simulation of Daily Deaths

Now to simulate daily deaths for 2020. So that the bar chart race can be easily updated, I’ll create a dataframe for the entire year so that all I have to do later is add in the new dates and the updated COVID deaths figures.

#this will be a slightly sloppy way of doing this but oh well
for (i in 2:34){
#that gives you annuals; the averages are over multiple years in which some are leap years, some are not, so divide the annual totals by 365.25 to get dailies
#anything that is below 0 we will just set to 0; I think the only one where this happens is terrorism because annual deaths are so variable for it
for (i in 2:34){
#and, finally, to apply the seasonality figures; and yes, I am aware that not all causes of death will have seasonality associated with them; this is in a way stacking the deck against COVID in the comparison to give a "fairer" comparison a la criticism received to date
for (i in 2:34){
#finally, to calculate cumulative figures for each column and round them to make it neater
for (i in 2:34){
#remove month and seas_adj
#save as csv using whatever directory you wish


Voila! Now you would pull the COVID causes of death as outlined in the previous post and put them into Flourish as shown. From there you get the new bar chart race. Enjoy!