How to Build a Bar Chart Race on COVID-19

Using the new Tableau version 2020.1 onwards

To build a bar chart race is to create many discrete pages of bar charts and then string them together, just like how a traditional cartoon animation is built. In Dec 2019, Tableau released 2020.1 beta version with a new Animations feature for dynamic parameters. This means that the bar chart race below is now very easy to build.

Pre-requisites

Download and install Tableau Public (latest version 2020.1.2 onwards). It is free of charge with full functionality. The only snag is that any work done can only be published on the Tableau Public server, and not saved locally to your Desktop. This is alright if the data is not sensitive or private.
Download the latest COVID-19 data (in *.xlsx format) from the European Centre for Disease Prevention and Control website, and rename it using a generic filename “COVID-19-geographic-distribution-worldwide.xlsx”. You can replace this file with the updated data later, using the same filename.
Open the Tableau Public app, and connect to the downloaded data file (click on “Microsoft Excel”). Click on the “Sheet 1” tab at the bottom left.
Connect Tableau Public to dataset

Identify the Quantity to Race

There are 2 useful quantities you can choose to race in this dataset:
Daily Infected Cases, or Daily Deaths Cases.
To choose the race quantity as daily infected cases:
Drag “Cases” to Columns.
To label the bar chart with country names:
Drag “Countries And Territories” to Label.
To have the bars in various colours:
Drag “Countries And Territories” to Colour.

Create Rank for Countries

This section requires a simple programming line of code.
Click on Dimensions → drop-down menu → Create Calculated Field.
Create a new field “Rank”, and key in the code below.
RANK_UNIQUE(Sum([Cases]))
To code for Calculated Field “Rank”
Click on “Apply” to ensure that calculation is valid, then click “OK”.
Drag “Rank” to Rows.
Click on (Rows) Rank → drop down menu → Discrete.
Click on (Rows) Rank → drop down menu → Compute Using → “Countries And Territories”.

Configure Animation (New Feature for Ver 2020.1)

To create a snapshot of animation frames:
Drag “Date Rep” to Pages.
Click on (Pages) Date Rep → drop down menu → Exact Date.
Turn on animations:
Format → Animations → On.
To set the transition duration: Duration → “1.00 seconds (Slow)”.
Close Animations window by clicking “X”.
Look for a little Animations control which appeared when the animations feature is turned on, and click the “forward play” icon. Drag the slider bar to a different date or use the left/right button to choose a date.
Animations control

Add Simple Customisation

1. To improve colours:
Click on Label → ensure “Show mark labels” is checked.
Click on Colour → Edit Colours -> replace similar colours if any.
(I have replaced the colours for USA, Spain, Italy)
Hide the Countries legend card, no need for it anymore.
2. To add additional labels for the number of cases to the bars:
Drag “Cases” to Label.
Click on Label → Text → click on “3 dots”. This opens up the label editor.
Arrange labels to 1 line only.
Underline <Countries And Territories>.
Bold <SUM(Cases)>, and use red font.
Click on “OK”.
Label editor
3. To change sheet name:
Double-click on “Sheet 1”, and change it to “COVIT-19 Daily Infected Cases”.
4. To change X-axis limits:
Double-click on the X-axis, this brings up the Axis menu.
Choose Range to be “Fixed”, Fixed start=0, Fixed end=40,000.
5. To display only the top 15 countries:
Drag “Rank” to Filters → click on “OK”.
Click on (Filters) Rank → drop down menu → Compute Using → “Countries And Territories” .
Replace “206” with “15”, and click on “OK”.
Change the Standard view to “Fit Height”.
View chart using ‘Fit Height’
6. To increase label font size:
Click on Label → Font → drop down menu → change to font size “15”.
7. To add date label on chart:
Right-click on the empty chart area → Annotate → Area.
This brings up the annotation editor.
Key in <Page Name>, and increase font size to “20”.
Click on “OK”.
The date label is created. Resize and locate it at the bottom.
Annotation editor

Publish Visualisation

When you are satisfied with the customisation, the visualisation is then ready to be published.
Click on File → Save to Tableau Public.
The work is now published on the Tableau Public server. You can then share it using the available link.
Here’s a video tutorial with step-by-step guide for the entire process:
A bar chart race becomes very simple to build using the new Animations feature in Tableau Version 2020.1 onwards. You can now try it on other country data with date/time series: GDP, Population, Life Expectancy, etc.
Let your creativity flow!

Comments

Popular posts from this blog

Permutation and Combination