April is upon us! I am loving the lighter mornings and start to longer days here in the UK – It does wonders for my mental.
Today, I am so pleased to be able to invite Nir Smilga onto the site. Its such an honour when people want to share there content on my site – very selfless of them. Nir has produced fantastic public work for years now, I’d urge you to check out his profile.
Most recently what caught my eye was a design technique of having small multiples, but rather than split each line losing the ability to cross compare, instead have them all showing and highlight each specific dimension. It just ticks the box for me between functionality and design. Over to Nir to discuss more at length…
Nir: I love small-multiples (a.k.a. trellis charts). They are one of my favorite data viz techniques. It allows each group to be shown without the clutter of spaghetti charts or stacked area charts. I wrote about it here including the “how to”.
But small-multiples lack the context of the other categories that makes comparisons easier.
Small-multiples charts include many data points. In this example each country is shown with a specific measure over time. It is difficult to look at one and compare it to the other countries, especially if they are not on the same row. To mitigate that I added a reference line, but still, it is not easy to compare. A neat solution is to use small multiples with all categories grayed out.
Seeing Yan Holtz do it in r gave me the push to finally try it in Tableau.
It took me quite a few iterations but eventually I did it!
Here is the first iteration:
And then I could not resist and created an enhanced version using map layers
This blog will focus on how I did it in Tableau.
I am not about to get into the bits and bytes of a “regular” (without the grayed out categories) small multiples chart in Tableau. I wrote about it in the blog I mentioned above. Another helpful resource Here is a very detailed tutorial by @sqlbelle explaining the logic and math behind this.
Small-multiples chart in Tableau is based on table calculations that create a grid or a matrix. It is determined by the number of categories of a specific dimension, in this case the country.
So in order to create the grid we will have to tell tableau to compute it for each one of the countries.
But here is the challenge: how to tell tableau to show for each category the highlighted country and all of the other countries at the same time?
The example I am about to demonstrate is a mix of the two versions presented above.
I will demonstrate a rather simple version using dual-axes: one axis for grayed out lines and the other for the highlighted countries.
I will use the data of the second example (Share Prices from the OECD) and show the highlighted countries as areas.
We need to break the grid by country but still need to show all the countries at the same time.
After thinking about it for a while, I had an Idea of joining the data to itself (self join) on the date field (which is the x-axis of each of the categories (countries)
So for each country we get all the other countries as well
First, we would like to filter the data, and allow users to remove and add countries.
As we have two country fields (as we applied self join) and we want the user to select or remove a country once and not twice, I created a set from the Location field and then created a mutual filter:
Now users can add and remove countries from the set and it will appear on both Location and LOCATION (Share Prices feb231) (self joined Location) I also filtered the data to apply to the latest 6 years.
We need to tell Tableau to create the grid by the Location, and add to the details the self joined Location- LOCATION (Share Prices feb231) .
Let’s start building the grid based on x and y coordinates (read the blog and watch the video to understand the logic behind these calcs)
Let’s add the date to the columns (wrapped by ATTR), the Values and again values, this time from the self joined table
Grayed Out lines Value (Share Prices feb231):
After adding the self-joined Value (Share Prices feb231) to the rows,
Let’s choose line chart type, and add Location, LOCATION (Share Prices feb231) -which is the self joined country, and date (make sure it is Exact Date and not aggregated) to the details, and date again to the path mark to make continuous lines
Highlighted Country Area Chart:
On Value (Share Prices feb231) (creating another y axis) let’s choose area chart type, and add date and Location on to the details
Now we need to tell tableau to compute the table calcs of x and y by the Location, Date, and All LOCATION (Share Prices feb231) fields, by editing its table calculations (the order matters!)
We should have something like that.
I suggest you don’t force the y axis to start from zero as we are showing trends\change vs 100 and not size comparison (which will require the y axis to start from 0)
Now, once the basic structure is set, we can focus on adding more context and on design.
Dual Axis to combine the views, gray color with lower opacity for the area chart
Space for country and value labels on both sides of the charts
For that we will use reference lines with these calculated fields
We want that space to dynamically change upon different layouts (# of columns) and different date selections.
Basically, this formula adds 5% to the left and right of the time period and multiplies by the number of columns.(make sure to hide the lines and the labels- we only need that for space)
Labels for grayed out countries
Let’s create a calculated field to show all the countries besides the highlighted country (we will treat that separately next)
* As we add another dimension, we will need to tell tableau to take it into account in the table calculations for x and y. We will continue to add all the newly created dimensions to the table calculation under the “Compute Using” section
Value label for all countries except highlighted
Note that the value is from the self-joined table
Now we will add these next to each other in the Edit Label section
Labels for grayed out countries
This is for the area chart, where labels are less customizable than on line charts.
We want the labels to appear to the right of the area chart and show the country name, the value and change vs the min date value.
In order to push the labels to the right I needed (after many tries and errors) It worked by adding the LOCATION (Share Prices feb231) field onto the details (and also to the x,y table calculations). To be honest, I am not sure I can explain here why it worked 🙂
Ok, now we will need to create a bunch of calculated fields
You can copy the calc text from the downloadable viz here
They are called
- Location Label
- Value Label
- PoP Value % Label
- and finally the ▼▲ signs, under Pop Value % ▲
* Remember to add all the new dimensions to the table calculation “compute by”! *
Let’s add some colors shall we?
- Line Color – assigns green to the highlighted countries with positive change, red to negative change and gray for the grayed out countries
- Area Chart Color – colors the area for the highlighted countries
Note: Change its opacity to 1%
- Let’s make the highlighted country line thicker by distinguishing it using a calc field.
* Remember to add all the new dimensions to the table calculation compute! *Labels Color (for the highlighted countries)
I finalise my visualisation by adding more context to allow better comparisons. I would like to also see how different countries responded to major exogenic events such as COVID19 and Russia’s invasion of Ukraine. Also, the values here represent changes from 2015 prices, when all values were normalized to 100, so let’s add this one as well. Russia invaded Ukraine on Feb-24th 2022 but since the date granularity it monthly I moved it to Mar-01-2022*
A few final touches to title and labels, and there we have it!
Downloadable the full viz here
In the published viz there is an additional sheet with a line chart version, that allows hovering over all the grayed out categories (you can get to it once you edit the viz)
I hope you find it useful – Share your thoughts!
A lengthy guest blog today jam packed with information and takeaways. We have everything from how and why trellis charts can be used through to additional tips and tricks when formatting. I love Nir’s ability to create the thicker line for the country that is being looked at. The padding Nir creates either size of the viz with labels really brings that next level of context to the visual. Can’t wait to see individuals emulate some of these design practices in their own small multiples moving forward. Thanks Nir!