Sitemap

Small multiples with grayed out categories

9 min readApr 4, 2023

Background

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 made it work!

Here is the first iteration:

https://public.tableau.com/app/profile/nir.smilga/viz/ConsumerConfidenceIndex/OECDCCI

And then I could not resist and created an enhanced version using map layers:

https://public.tableau.com/app/profile/nir.smilga/viz/SharePricesbyCountryOECD/OECDSP

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

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.

Data prep

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.
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:

*I am placing here the calculations images from Tableau, you can copy the calc text from the downloadable viz here*

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.

Layout

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 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)

More context and design

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) to add 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

*I am placing here the images from Tableau, you can copy the calc text from the downloadable viz here*

First ,the country label for the highlighted country line:

And the value label:

Then, to show the change between the max and min period values for each country:

And finally, the labels and ▼▲ signs:

* 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:

Labels Color (for the highlighted countries):

Reference lines:
I would like to add 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.

The calcs:

*Russia invaded Ukraine on Feb-24th 2022 but since the date granularity it monthly I moved it to Mar-01–2022*

Title — In the title we want to add the countries with the largest and smallest change.
Here are the calcs (We had to use Fixed LODs to aggregate the whole date range:

Also, 2 calcs for the largest increase are done in the same manner.

Same as we did for the labels, we will color the decrease in red and the increase in green:

And there we have it!

Downloadable link:
https://public.tableau.com/app/profile/nir.smilga/viz/BlogSmallMultipleswithgrayed-outcategories/SharePrices-DualAxis-Area

Final thoughts

For this data viz I used self-join to show both the highlighted country and the grayed out lines for all the other countries. This requires an expensive Cartesian multiple. I couldn’t make it work without it, but maybe there is a way to avoid the self-join?

In the published viz above there is an additional sheet with a line chart version (rather than area), that allows hovering over all the grayed out categories (you can get to it once you edit the viz) maybe you’ll prefer it?

Using map layers (as I did in the 2nd viz I showed above) will allow the benefit of both , as well as additional attributes such as country flags and more, but that’s for another time.

I hope you find it useful
Share your thoughts!

Nir

--

--

Nir Smilga
Nir Smilga

Written by Nir Smilga

Passionate about data, insights and visualizations, Tableau featured author

Responses (3)