Layering data for custom Tableau visualizations

This post outlines a method that has been shared before in the Tableau community. I was initially introduced to it by Noah Salvaterra’s Chord Diagram a while back. 

I am going to walk you through a layering technique, which allows use, and re-use of a single axis in Tableau. This can be done at different levels of granularity, different fields entirely or completely synchronized throughout, thus it can adapt pretty well to various use cases. Need to create a dual-axis in a single axis? This technique can enable this for us (as long as you need the same mark type that is). 

So What? With this technique you can build more detailed and very customized visualizations directly within Tableau (without the need for extensive data prep).

Two other quick call outs, one is the circle math I use here. I have adapted it from Joe Mako’s handoff map (a Tableau classic!). A quick aside, be sure to check out what Steve Wexler recently wrote about Joe and Kelly and their incredible impact on the Tableau community. The second is that I came up with the viz below only after seeing this work by Nadieh Bremer. The layout of my viz obviously mimics her layout based on a similar dataset.

By “layering” in this context I refer to building a number of separate visualizations and then overlaying them on top of one another. This is one reason why you can do so much in d3.js when it comes to custom data viz. There is really no limit to the number of layers and formats that you can stack together in the browser (just don’t load too many elements into the DOM). This technique in Tableau does have a few limitations of its own, for example, the number of marks you are rendering can grow to be quite large. Also, you are limited to only two mark types (e.g. lines and circles for example) in the viz you build.

Here is an example I built out using some data I gathered on the PBS Kids show Word Girl, the current (and VERY much) favorite of my 3 and 6 year old daughters. If you want to hear the theme song, un-mute your speakers or plug in your headphones. Also, I have to give Jonni Walker a shout out for some design help, especially in making the edges glow like Word Girl’s flight trail. Full disclosure, I did learn some new word definitions while working on this project.

You can also visit the interactive version on Tableau Public here

First thing we can take a look at is the deconstructed layers of the view. Here they are: 

You can see the parts of the viz are parsed on the value “Copy”. Just as Noah demonstrated in his post, I am doing a join with my data using a very simple file that looks like below: 

Now that we have layered (aka union'd) the data, we have what we need to do the same in our viz. There are just a few key steps to make this happen

Identify each layer using the field “Copy” (or whatever you called it). You can then set the level of detail of your viz with a simple if or case statement. Here is mine for the above example...

Now for each copy we can do whatever calculations we need at the different levels. My visualization is a multi-level circle, so for me, depending on the layer we are going to calculate either the inner, outer circle coordinates or the edges. With my different layers I am doing the following:

  • Plotting the villains in alphabetical order, clockwise from 12 o’clock, sized by appearance.

  • Drawing edges from villains to episodes they were in.

  • Plotting episodes (colored by season for the write up) clockwise from 12 o’clock. Note there are two copies of this, this is to allow for different tooltips based on interactions.

  • Plotting the vocabulary words of focus in each episode as pedals/satellites around each episode.

Here is an example of a single pill that based on copy does each of these above things.

I have similar equations on the y-axis which you can reverse engineer from the viz itself. With this technique, you can think of it as creating additional "Marks cards" for each layer of your data. Those cards are then accessible via the variable "Copy" and this can be used again and again; to draw marks, specify tooltips, specify labels, etc. 

Hope you find the technique helpful/useful as I did and let me know if you have any questions.

Bonus section: Calling the Oxford Dictionary API with Alteryx

Alteryx flow which pulls word definitions from https://developer.oxforddictionaries.com

The data I initially pulled from PBS Kids had a list of the vocabulary words each episode focused on. One thought I had was that I should really include the definitions for these 621 words (554 unique), that’s what Word Girl would do! So it was decided, question was how...

After a little research (aka a single Google search) I found the Oxford Dictionary API. Thanks to Alteryx I was able to then use this API in just a few hours. I was able to define 620 out of the 621 words I had from this process, so was more then happy with that result. This is what powered the definitions in the viz when you mouse over each word.

To do this in Alteryx we use the web download tool with our API credentials (app_key and app_id) declared as fields on the headers tab. I sent into this web download tool a list of my vocabulary words with api call URL (https://od-api.oxforddictionaries.com/api/v1/entries/en/) prepended to the word, a simple string concatenation formula. I did have to throttle the API call, and I output the resulting payload into a staged Alteryx database file so I was not repeatedly calling the API for the same data. 

From there I utilized the JSON parse tool, followed by a couple filter tools to pick out the specific key-value pairs of data I wanted, joined them back together and that was it. This data was ported into Tableau and used for the definitions in the tooltips when mousing over specific words. 

Bonus section 2: Changing parameters with URL Actions on Tableau Public

One of the effects that I wanted to achieve was some custom highlighting. I ended up implementing this via a parameter and some calculated fields across my different sheets Once that was all working, I had to implement a little trick in order to make this change available to the end user via a simple dashboard action (select action in this case). If you haven't read Jonathan's recent post on the subject, definitely check it out. What I ended up doing was using an URL action, pointing to the dashboard with a few specific additions and one trick that Rody Zakovich reminded me of (thanks Rody!). Here is the URL from my dashboard action: 

https://public.tableau.com/views/WordGirl/WordGirl?:showVizHome=no&:embed=y&:tabs=no&:linktarget=_self&Villains=<AGG(Dimension Villain Densified)>

From this URL, &:linktarget=_self tells Tableau to render the viz back into same container (e.g., not open up a new window). Secondly, I pass the new parameter value via &Villains=<AGG(Dimension Villain Densified)>

The last piece of this, in order for it to work in a single page on Tableau Public, was to create a blank dashboard, put a web page object onto the dashboard and point that web page to the "share" link of the actual dashboard with &:linktarget=_self appended to the URL. 

This is not necessarily perfect, as the whole dashboard is re-loaded on each action, vs just updating. However, it does work and keep the user on a single screen while interacting with the viz.