Creating Comet Charts in Tableau
A recent Makeover Monday covered the topic of Life Satisfaction, and if it was correlated to Gross Domestic Product (GDP). The dataset included a Life Satisfaction score and GDP for various countries over time. In my viz I used a Comet chart to tell the story of how counties have changed between 2010 to 2017, relative to the other counties within each continent.
I think Comet charts are a great way to visualise lots of attributes about a data set in a very digestible way, particularly for people who are not experts in data visualisation.
In this blog I am going to show you how to create Comet charts in Tableau.
Note: The viz also included the use of country outlines, and Parameter Actions to control the Comet chart viz. I won’t be covering these in this blog, but please reach out if you would be interested in understanding these. You could use the approach described below to create a Comet chart for any dataset, however, if you would like to replicate the viz in this blog, the original dataset is here.
First off, what is a Comet chart?
A comet chart is a line between 2 data points, with a sizing applied to these data points to enhance the ‘direction of movement’ between them. This is a great way to visualise performance over time when also correlating 2 measures.
In the case of the comet chart in this viz, I have used a scatter plot to show the relative position between 2 measures (Life Satisfaction and GDP per Capita) and have shown the relative ‘direction of movement’ between 2 different years (2010 to 2017). The movement between the years is accented by sizing the 2017 larger than 2010 (the Comet effect). This has been further enhanced with the use of a custom sequential colour.
This viz allows the reader to:
Quickly see the positioning of Life Satisfaction and GDP for the individual countries.
To understand if each country has seen a shift in their positioning between years, and if it is Life Satisfaction or GDP driving it.
To understand this shift in position relative to other countries in the same continent.
I initially extended the scatter plot out to include all countries, however I decided to then limit it to only show the countries within the same continent. Since continents can have such different ways of life, I didn’t feel this was a fair (or relevant) comparison.
Building the Comet chart viz
Choose the 2 measures you want to be part of the viz, and put one on Columns, and one on Rows.
In order to bring in the data for each country, move the Country Dimension onto Detail.
Then filter the viz by putting the Region into the filter box, and then selecting a continent. In the example here I chose the ‘Middle East’.
Next, change the Mark Type to Line. The viz will look something like this:
Don’t worry, you haven’t broken Tableau! At this point, Tableau doesn’t know which way to draw the line, so it takes a default position. We will now tell Tableau how you want to draw the line.
Move the Year dimension to the Path Mark.
Move the Year dimension to the Filter Pane, change to discrete, and then select 2010 and 2017. (I could have included more, or all of the years data at this point, however I decided I only wanted to focus on the movement between 2 years, not all of the ones in between as this would have created a very busy viz.)
The viz will then look like this:
The viz now shows the line between 2010 and 2017, by country. To now bring out the ‘direction of movement’ between 2010 and 2017, create a calculated field which will tell Tableau that you want to treat the size of the 2017 data point differently to the 2010 data point.
Drag this calculated field (I called this sizing) onto the Size Mark, and then again onto the Colour Mark, and you start to get the comet effect.
You now have the key building blocks in place for a comet chart.
From here, I tided up the viz:
Removed grid lines.
Changed the colour to a red custom sequential.
Removed ‘Include Zero’ from each axis to prevent too use the full space on the viz.
Moved ‘Country’ to the Label viz.
I then wanted to increase the size of the 2017 data point vs 2010, making the head of the comet slightly lager to really help the user see the difference in the years. To do this click on the drop down next to the Sizing key:
Change the ‘Sizes vary’ to ‘By Range’. Move the Mark Size Range to the sizes wanted (a bit of trial and error here to get the sizing you want).
The final viz then looks like this:
Comet chart done!
As I said at the start of the blog, I also used parameter actions on the dashboard to enable the user to select a content, and for this to filter the comet chart viz. If you would like to know more about Parameter actions and how I used them in this viz, please reach out to me, and I can always write a blog specifically on this.
I hope you found this a useful blog for creating Comet charts for yourself.
Feel free to get in touch on Twitter @garycollins24