One-Sheet Marginal Histograms

Oct 6, 2022

Klaus Schulte

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

Three-Sheet Solutions

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:

  • The sheets used in such a set up are normally set to fit the entire view. This limits options to parameterize/variablilize your axes. Proportions of your marginal histogram might only look good for the selected variables and unproportional or squeezed for other variables.
  • In this set up, you are not able to slice & dice your marginal histogram, e. g. to create a small multiple of marginal histograms to break down your analysis to one or more dimensions. You could do that with filters, but wouldn’t be able to see all of the results at the same time.
  • It can be a pain to bring these sheets together on the dashboard, especially when working with tiled layouts. You’ll have to use containers to align everything properly, set padding accordingly etc.
  • Also, you might want to scale the bar charts properly to be able to compare the length of the bars across both charts. In this set up, height of the upper and width of the right bar chart had to match, and then you’d have to work with reference lines across the two charts to set the maximum value.
  • Filters always have to be applied on all three sheets. Keep that in mind when using quick filters or dashboard action filters.

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.

Tableau Map Layers

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:

  • X = datepart(‘month’,[date])
  • Y = datepart(‘weekday’,[date])
  • Geometry = makepoint([Y],[X])

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.

One-Sheet Solution

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.

Variable Inputs

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

Slice & Dice

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.

Other challenges

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.

Wrap Up

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!