Creating a Chord Diagram with Tableau Prep and Desktop

Chord diagrams visually represent, in a circular form, the inter-relationships between entities in a matrix, with curved connecting lines between entities.

For a recent visualisation I was showing the flow of remittances between world regions and I thought this was a good use case for a chord diagram. A quick google search turned up this excellent tutorial blog post by Luke Stanke where he prepares data using R and provides a chord diagram Tableau workbook template file.

I decided to replicate the data preparation steps in Tableau Prep and, in the build process, ended up modifying the workbook template by removing the outer bars and adjusting a few calculations to make the chord lines start thicker and become thinner as they reached their destination.  Below is the final chord diagram I used:

Creating a Chord Diagram Template

I thought a template Prep workflow that you could feed a matrix of data into, as an Excel sheet, and it outputs a Tableau data source to use with template workbook would be a helpful resource, so I modified the Prep flow to be more generic and added comments and instructions in the flow.

This blog will walk through how to use the Tableau Prep flow and a Tableau Desktop template workbook to create a chord diagram of immigration flows between countries within the EU using the latest data I could find from the World Bank (2017 numbers).

Note – all credit to Luke Stanke for the trigonometry and other calculations for the chord diagram in the workbook template. I have just made some formatting changes and simplification of the final version as mentioned earlier and added accompanying bar charts to the workbook.

Template Files

Download the following three files to follow along.  If you don’t have Tableau Prep you can download a 14 day trial version here.

Tableau Prep Flow Overview

For details of each step, it will be easier to look at the flow itself within Tableau Prep so you can see the calculations and join conditions etc., however, below is a high level summary of what the workflow is doing.

Tableau Template Overview

I’ve added some bar charts to accompany the chord diagram to allow easy visibility of exact values and also to act as a means of selecting the dimension value to highlight in the chord diagram, which you can do by clicking on one of the bars in the top bar chart:

The top bar chart shows total values for each ‘from’ dimension. The bottom bar chart shows values for each ‘to’ dimension filtered to the selected ‘from’ dimension, such that values for all bars in the bottom bar chart will add up to the value of the selected bar in the top bar chart.

There is also a grid view of the data, so you can look up individual values if needed. Click the grid icon in the lower right to access this.

EU Migration Data File Overview

This file is a cut down version of a larger bilateral migration file from The World Bank (source). I reduced the number of countries included to only those within the EU as of 2017 to give a suitable number of nodes to represent in the chord diagram.

You could use your own file that has a similar matrix structure. One requirement is that cell A1 in the top left of your spreadsheet should contain the text “Dimension” as that is referenced throughout the Prep workflow.

Create a Chord Diagram

The below steps walk through how to use these three files to create a new chord diagram by:

  • Replacing the source data in Tableau Prep and creating a new output hyper file
  • Updating the Tableau Workbook to use the new hyper file

Replace Data Source in Tableau Prep

  1. Open the Prep Flow and delete the existing data source
  2. Add the EU Migration spreadsheet file that contains a matrix of values and connect it to the Pivot step
  3. Reconfigure the Pivot by first deleting the old dimension values (which are no longer valid)
  4. Add all new dimension values to the pivot column, except the value “Dimension”
  5. Change the output file name in the final Output step of the flow to “EU Migration Output.hyper” or similar
  6. Run the Prep workflow to generate the hyper file

The below video walks through the above steps

Update the Tableau Workbook

  1. Open the template workbook (downloaded earlier)
  2. Add the hyper file created in the previous step as a new data source to the workbook
  3. With the new data source selected, move the “Rank” and “Rank2” fields from the Measures section of the data pane to the Dimensions section
  4. To maintain the same colours, copy the “Selected From Dimension” from the old data source to the new data source
  5. Right click on the old data source and select “Replace data source” to use the newly added hyper file
  6. Update the “p.Number of Nodes” parameter as required (this will be the total number of unique dimension values, which, for the EU migration file, is 28)

The below video walks through the above steps

Hopefully, you now have a working chord diagram!

Note, if you are making further updates to your Excel data source, you can just close the Tableau workbook and re-run the Prep flow to overwrite the hyper file. When you re-open the Tableau workbook it will use the updated hyper file, so no need to swap data sources.

Change Formatting and Dashboard Size

Depending on the number of nodes you have and the relative sizing between measures you may need to adjust the size of the lines using the size control on the marks card. 

A few other calculations you may wish to adjust for visual appearance are:

The Size calculation:

The Point Size calculation:

Resources

If you use this template, please credit @lukestanke for his original work. Thanks!

Marc Reid
Twitter | Linked In | Tableau Public

The journey…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

WordPress.com.

Up ↑

%d bloggers like this: