One-Sheet Marginal Histograms
Oct 6, 2022
Klaus SchulteMarginal histograms are great to find patterns in your data. Especially when working with date or time fields, they’re one of my preferred chart type to start my analysis. Steve Wrexler has written about the usefulness of marginal histograms in more depth in this blog. Make sure to check it out (and all other blogs on Steve’s blog 😃).
In this blog, I’d like so share some insights and thoughts on how to create them in Tableau.
Normal way to create marginal histograms in Tableau is to create separate sheets for the heat map and the two bar charts and then to bring them together on a dashboard, like I did in this example available on my Tableau Public profile.
When you look into that workbook, you’ll see three floating sheets. These three sheets together build that marginal histogram as a whole.
This approach is absolutely doable, but it comes with some limitations regarding flexibility and scalability:
Sounds like a lot of disadvantages. Before looking at a one-sheet solution and comparing it to the three-sheet solution, let’s have a look at Tableau Map Layers, the feature needed to do a marginal histogram in one sheet.
If you’ve never used map layers so far, I recommend reading this blog by Luke Stanke to get started.
The idea – in a nutshell – is to describe all elements of your visualization as X-Y-coordinates, create geometries from these X and Y coordinates, and build your visualization step-by-step with as many layers as needed.
To give you an example, for a heatmap with months on columns and weekdays on rows, you can calculate the X- and Y-values and subsequently the geometry as follows:
Bringing in the geometry with a double click will then create a map:
You can then washout the background and get rid of the (actual) map in the background.
To create the heat map from this, we need some densification, since a rectangle can only be drawn from 4 points. Therefore I’ve brought in another table with four records representing the four copies of the data needed to build that heatmap and connected both tables with a relationship calculation on 1=1.
If you check the workbook with my one sheet solution, you will then see how I used the [Copy] field to build my heatmap coordinates. I also parametrized the further inputs, like [Size] for the width and height of each rectangle and [Gap] to bring in some space between the elements.
For the X-variable:
For the Y-variable:
If I then use these fields in my geometry field, I get this:
To build the heatmap from here, I have to switch to the polygon mark type, bring in my two datepart variables on detail, and [Copy] on path to tell Tableau how to connect the points.
That’s the basic concept, and from here you should be able to reverse engineer my workbook. All other elements are constructed in the very same way and brought in as additional map layers.
Now let’s see how a one sheet solution tackles the challenges with three-sheet solutions I’ve described above. You can also play with my workbook on Tableau Public.
First thing you’ll noticed is that I’ve variablized the x- and y-axes. You can select the dateparts you want to show on Columns and Rows from two parameters.
The length of the bars scale accordingly and each combination of the two dateparts result in a good looking visual where the longest bar is always half as long as the side with less dateparts (e. g. with 7 weekdays and 12 months the length of the longest bar is 3.5).
You can easily slice & dice a one-sheet solution to break down the marginal histogram on one dimension.
Or even better, break it down on two dimensions.
Regarding the scaling challenge I’ve implemented calculations to have the same proportions across the two bar charts. That makes it easier to compare the variables on X and Y or across marginal histograms when breaking them further down.
Filtering is also easier in a one sheet solution. Just bring in the filters as needed, but make sure to implement set filters or context filters since FIXED LODs are leveraged in the calculations (or figure out the INCLUDE and EXCLUDE LODS instead to be able to use dimension filters as well 😉).
And finally, forget about all the formatting you need to do with a three-sheet-solution. Just bring in that sheet, and you’re ready to go.
As could be shown, a one-sheet solution comes with some advantages compared to the three-sheet solution. However, one cannot deny that it’s definitely not straight forward to create such a viz, but possible if you want to do that invest. Eventually, it might depend on the specific use case, if you should go for a three- or a one-sheet solution.
I’ve you’ve found this useful, leave a comment below or reach out to me on Social!
COMMENTS