A Graph Recreation in Tableau - Part 2: How To Build

I received a number of pings about yesterday's post showing the sankey-style slopegraph in Tableau (here). Here are the basics of the recreation using calculations in Tableau to simplify the process even further.

Original graph is here.

NOTE: New blog post 5/9/2019 explaining new method and formula posted here using SIN() instead of Sigmoid function.

INSTRUCTIONS UPDATED 4/4/2014- Thanks to Tableau Zen Master Jonathan Drummey for pointing out that the previously used Xval field is not needed. It's now simply replaced with t.

To create this visualization I use the Sigmoid Function: S(t )=1/(1+e (-t ))
(more information here.)

In Tableau I use the function EXP(1) for e. So we need the input variable t. Therefore we need 4 fields.

State, 2012 Ranking, 2013 Ranking, t

To get the shape of the line I am going to plot 49 points for each state (49 was simply used to get enough points to plot the shape of the curves and is the same number of values in t ).
t = a value between -6 and 6 in .25 increments (which is 49 values)

The data file is available here so you can load and follow along in Tableau. There are 3 extra fields in the Excel file to show the calculations, but they are not needed in Tableau.

Step 1: Open Tableau and Import Data

Step 2: Create some calculated fields

   Calculated Field Name: Sigmoid Function
   Formula: 1/(1+EXP(1)^-[t])

   Calculated Field Name: Curve
   Formula: [2012 Ranking] + (([2013 Ranking]-[2012 Ranking])*[Sigmoid Function])

NOTE: Formula Updated 4/8/2014- Thanks to Catherine Rivier for offering a much more elegant solution than the original formula.

   Calculated Field Name: Color
      IF [Curve] <10.5 then 1
      ELSEIF [Curve] <20.5 then 2
      ELSEIF [Curve] <30.5 then 3
      ELSEIF [Curve] <40.5 then 4
      ELSE 5 END

   Calculated Field Name: Size
   Formula: ABS([2013 Ranking]-[2012 Ranking])

Step 3: Build the Viz

   Move t to Columns
   Move Curve to Rows
   Move State to Details
   Move t to Details and Convert to Dimension
   Set Marks to Line
   Edit X-Axis to Fixed with Start = -6.5 and End = 6.5 (the extra .5 allows room for the labels)
   Edit Y-Axis and Reverse Scale
   Move Size to Size
   Move Color to Color
   Edit Color using Stepped Color with 5 Steps
   Uncheck "Show Header" on Y-Axis and X-Axis
   Move State to Label
   Select Left most points (at X = -6) and Select "Always Show" under Marks Label
   Repeat for Right most points (at X = 6)
   Format Curve to Number Format with 0 decimals
   Move Curve to Label
   Format Label to "<SUM(Curve)>. <State>"
   Format Sheet Lines to remove Gridlines and Zero Line (set to "None")
   Format Sheet Borders to remove border (Row Divider and Column Divider Pane to "None")
   Format Font Style/Color and Viz Spacing as needed

   UPDATED 4/2/2014
   Click Color on the sheet and set "Markers" to "None". This will remove the dots at the end points.

You should now have a visualization that looks like the example. Use ColorPic (free color tool) to get the colors just right and import into the Tableau Preference file using type="ordered-sequential" for this categorical color scheme.

I hope you find this helpful. If you have any questions feel free to email me at Jeff@DataPlusScience.com

Also, check out the visualizations in the Elite 8 of the Tableau Sports Viz Competition and vote for my Viz here!

Jeffrey A. Shaffer
Follow on Twitter @HighVizAbility