More options for your Tableau Sankey Diagram

A quick look around Tableau Public can often lead you to a Sankey diagram at some point. I can only speak from my experience, but the majority of these visuals (including mine thus far) leverage the sigmoid function. This technique has been posted about and presented on (including by me) quite a few times across the Tableau community, I first found it on Jeff Shaffer’s Blog and this has of course morphed many times and ways, for example, some of the great work done by Olivier Catherin to build a Sankey leveraging polygons (also found on Jeff’s Blog).

Not so recently, Tableau came out with some improved dashboard spacing capabilities in version 10.4. I had been awaiting this feature for a while and could not wait to update some of my Tableau Public work in order to take advantage of it (granted it took me a while to do so). Now we can get rid of those annoying spaces which have been forced into our (tiled) visuals to date.

We can make this...

Look like this without having to float...

But as a result of this change, something became much more apparent, especially if you obsess over pixel perfection. Do you see it? How about if I zoom in a bit on the above picture...

Off just enough to drive you mad, isn’t it? I was brainstorming with Rody Zakovich about what the causes of this could be. We went through all of the various layout gotchas in Tableau, and came to the conclusion (his suggestion) that it has got to be the math. After a bit of investigation, I found that sure enough, it was the math. The sigmoid function math I was using served its purpose, but also ended slightly off from where it was supposed to. Instead of ending at 535, my curve is ending at 534.82 and so on. The result of this in my viz, is the imperfect pixel alignment which is now, much more obvious when these two sheets are truly bumped right up next to one another. So what now? We cannot stand for this pixel imperfection...

Well, what we can do now is morph this technique once again and change up the math used for plotting the curve. I took a shortcut here and adapted the math from D3’s easing functions which also have a great visual explanation by Mike Bostock here

Porting a selection of these easing functions (as not all are applicable) is an exercise in converting JavaScript formula syntax to Tableau formula syntax. The good news is that I went ahead did all that for you. You can just go ahead and copy the calculated fields into your own workbook as I demonstrate below. Here is a Tableau version of the visual explanation of the easing functions (less animation).

And here is how the calculated easing formula looks in Tableau. I decided to add two parameter toggles so you can easily switch between the formula and pick the resulting curve visual that you prefer for your viz.

Now, here are the steps you can follow to implement this technique in your own work. Note: This assumes you are leveraging densification and have an existing Sankey that you are modifying. For details on how to create a Sankey, check out Jeff's aforementioned posts.

  1. Save a copy of your work as we may break some things as we go.

  2. Download the example workbook below. This workbook is an example of a polygon Sankey, if you want a line Sankey workbook check here.

  3. Copy the fields and parameters listed here for the ease formulas needed and paste them into your workbook (select, copy and paste all of these at the same time):

    • Densification

    • Densification (bin)

    • Densified PI

    • Index Ease

    • t

    • Easing

    • Easing Type (Parameter)

    • Curve Type (Parameter)

  4. If you were using sigmoid function before, you should be able to just replace the sigmoid function with these easing functions. Your formula probably looks like below:

    Start Position + (End Position - Start Position) * Sigmoid

    will need to be changed to

    Start Position + (End Position - Start Position) * Easing

  5. The last step is that you may need to adjust your table calculations, I start by replacing reference of your existing bin to "Densification (bin)". But be careful with that, as it could have a wider impact then you intended. From there it is just double checking your table calculations and their partitions. 

Here is the example workbook, change the two parameters to see the different options you will have with this technique.