Sankey Diagram for Cohorts 2


Facebooktwittergoogle_pluspinterestlinkedinmailFacebooktwittergoogle_pluspinterestlinkedinmail

Sankey

In my previous roles I have had the need to visualize cohorts i.e. for all the people that became members or subscribers who many are still with us and how many have moved on. There are many ways of visualizing this information but I have found a Sankey Diagram very appealing. In this step by step tutorial we will build a Sankey Diagram based on a fictitious gym.

Before you start with this tutorial please see the Dashboard on Tableau Public by clicking HERE

The Data Set

Before we get building we must understand at the Data Set which contains eight fields.

  • Month – This represents the month which will go into the columns. We have values 1-6.
  • Segment – Represents the individual pieces in each month. We have values 1-3
  • Segment Label – Presents the Good or Bad which is used for coloring our segments.
  • Splits 1,2,3 – Represents the size of the segments or splits. We have three different splits.
  • X – This is a number that is used to create the Sankey via a Sigmoid function. We have values -6 to +6 and 202 points per month to create a smooth line.
  • Path – This presents the individual points which allows us to draw our polygons for each segment.

Download the Tableau Data Extract HERE and double click to open this with Tableau Desktop.

sankey0c

Note: Part 2 of this article will go through the process of preparing your own data for producing this Sankey diagram.

Creating the Objects

With Tableau Desktop open with the Sankey Diagrams Data data set we will start by creating some parameters what will be used to adjust the dashboard.

  • Click the down arrow next to Dimensions and select Create parameter…
  • In Name type Split Selector
  • In Data type choose String
  • In Allowable values select List and add the following (for both Value and Display As):
    • Split 1
    • Split 2
    • Split 3
  • Click Ok

sankey0a

This parameter will be used to allow us to select to display different values or splits. To allow us to adjust the size of our Sankey Curve we will create another parameter.

  • Click the down arrow next to Dimensions and select Create parameter…
  • In Name type Signmoid Size Factor
  • In Data type choose Integer
  • In Allowable values select List and add the following (for both Value and Display As):
    • 1
    • 2
    • 4
    • 8
    • 12
  • Click Ok

sankey0b

We will now create some Measures for use within our Dashboard:

  • Click the down arrow next to Dimensions and select Create calculated field…
  • In the name type Math Path
  • Use the formula type

sankey1

  • Click the down arrow next to Dimensions and select Create calculated field…
  • In the name type Metric
  • Use the formula type

sankey2

  • Click the down arrow next to Dimensions and select Create calculated field…
  • In the name type Y
  • Use the formula type

sankey3

Building the Sankey Diagram

Now that we have created our objects we are going to build the Sankey Diagram step by step.

  • Drag Segment ID onto Color
  • Drag Month onto the Columns
  • Drag X onto the Columns
  • Drag Y onto the Rows
  • Right Click on Y, Compute using and select Segment ID
  • Change the Marks to Polygon
  • Drag Path onto Path

After this you should see the following

sankey4

Now we will focus on the cosmetic aspects:

  • Right click on the Y axis
  • Under Scale click on Reversed
  • Right click on the Y axis and deselect Show header
  • Right click on the X axis and deselect Show header
  • Right click on the visualisation and select Format…
    • In Format borders
      • Go to Row Divider, Pane and select None
      • Go to Column Divider, Pane and select None
    • In Format lines
      • Go to Grid Lines and select None
      • Go to Zero Lines and select None
  • Click on Color in the Marks Pane
    • Choose a bright colour for 1
    • Choose the same gray colour for 2 and 3
  • Right click on Month and select Edit Aliases…
    • 1 – Jan
    • 2 – Feb
    • 3 – Mar
    • 4 – Apr
    • 5 – May
    • 6 – Jun
    • Click Ok
  • Right click on the Month at the top of the visualisation and select hide field for labels for column

You should not see the following

sankey5

  • Drag Metric into the Tool Tips
  • Right click on Metric and click Format…
  • Click on Number format and change this to Percentage.
  • Click on Tool Tips and edit this to just show the Month and SUM(Metric)

Now you can explore your Sankey Worksheet and visually see how many people dropped off at which month. You can also hover over to see an actual 80% split. You can also use the Split Selector and Sigmoid Size Factor Parameters to customise your view.

Summary

We have now completed our Worksheet for the Sankey and now we just need to put this all together into a nice and interactive Dashboard. As you can see once you prepare the data this becomes fairly straight forward with the use of a few Table Calculations.

Sankey

Facebooktwittergoogle_pluspinterestlinkedinmailFacebooktwittergoogle_pluspinterestlinkedinmail

Toan Hoang

About Toan Hoang

Toan Hoang is a technology enthusiast with a broad understanding and appreciation of most aspects of technology but with a passion for Business Intelligence Solutions and Technologies, Data Management and Web Programming.


Leave a comment

Your email address will not be published. Required fields are marked *

2 thoughts on “Sankey Diagram for Cohorts