paint-brush
How to Build a Bar Chart Race on COVID-19 Cases in 5 Minutesby@jnyh
1,349 reads
1,349 reads

How to Build a Bar Chart Race on COVID-19 Cases in 5 Minutes

by James NMay 6th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Using the new Tableau version 2020.1 onwards onwards, you can build a bar chart race using the latest data from the European Centre for Disease Prevention and Control. Using the latest COVID-19 data (in *.xlsx format) you can choose the quantity you can race in this dataset: Daily Infected Cases, or Daily Deaths Cases. The only snag is that any work done can only be published on the Tableau Public server, and not saved locally. This is alright if the data is not sensitive or private.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail

Coin Mentioned

Mention Thumbnail
featured image - How to Build a Bar Chart Race on COVID-19 Cases in 5 Minutes
James N HackerNoon profile picture

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.

Watch it in action: https://www.youtube.com/watch?v=3iZrMkZ3948

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.


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]))


  • 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.


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”.

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”.


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.

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:

Let your creativity flow!