Treemap Chart is commonly used to provide a hierarchical view of data and makes it easy to spot patterns. There are many different ways to visualise data and in this tutorial we will talk about how to create a treemap in tableau.
I have been using this charts in my presentations and was very much interested in creating the same in Tableau. This tutorial is influenced by Taon Hoang and Ken Flerlage. I personally recommend an article by Ken Flerlage on Data Densification if anyone is interested to dig deeper in this topic.
Lets get started
Data
We will be using Sample super store data for this tutorial and data densification technique for creating a tree map chart using “Sigmoid Curve” using bins to artificially densify the data.
Once you connect to sample superstore data in tableau, right click on the data source and click on Edit Data Source. Once the data source ditor is open, paste the following:
Path
0
200
Once you do that, there will be a join window where we will cross join the new table to our data as below. Create a Join Calculation and type 1 on both the sides and you should see following.
We needed additional records as we will be using it to draw the Sigmoid curve using data densification process.
Calculated Fields
- Path (Bin):
- Right click on Path, go to Create and select bins
- In the edit bin dialogue box:
- Set new field name to Path (bin)
- Set size of bin to 1
- Click ok
@TC Sales
This field is used to get the windows sum of sales. Due to the join with range 0 -200, we got duplicate rows for each value in Sample superstore data. so we need to divide it by 2 to get the right number.
WINDOW_SUM(SUM([Sales]))/2
@TC_Total_Sales
We create another calculation for windows sum of total sales.
WINDOW_SUM(SUM([Sales]))/2
@TC_Percentage
This field is used to calculate the percentage
@Tc_Percentage_Adjusted
This is used to calculate the percentage based on windows max value
@TC_Rank
This field is used to create a unique ranking based on Sales value
RANK_UNIQUE([@TC_Sales],”desc”)
@X
To Plot the X coordinate
((INDEX()-1)*0.12)-6
@Y
This is to plot the Y Coordinate
@TC_Sigmoid
Equation of a sigmoid curve
1/(1+EXP(-[@X]))
@TC_Size
This field is used to calculate the size of the bars on the treemap chart
IF [@X] >=6 AND [@X] <= 6+(10*[@TC_Percentage (Adjusted)]) THEN
1
ELSE
0
END
We have now created all the calculated fields. now we can start building the visualisation.
Worksheet
- Change the Mark Type to Line
- Drag Sub- Category on to the colour Mark
- Drag Path(Bin) on to column shelf
- Right click on this pill and ensure that show missing values is selected
- Drag the pill to Detail Mark
- Drag @X to column Shelf
- Right click on this pill and go to compute using and select Path(Bin)
- Drag Y on to the row Shelf
- Right click on this pill and go to compute using and select Path(Bin)
You will see the following:
Will now adjust the Y Pill table calculation
- Right Click on the Y Pill and select edit table calculation
- In the nested calculation select @Y
- In compute using select specific dimension
- Select only Sub-Category
- In the nested Calculation select @TC_Rank
- In compute using select specific dimension
- Select only Sub- Category
- In the nested calculation select @Y
You will see the following:
We can then bring the Sales measure into the size field and we will see the following
We have now build the treemap chart, we will now work on creating a rounded bar chart on top of tree map chart.
- Drag @TC_Size onto the size mark
- Right Click on this pill and go to compute using and select Path(Bin)
- Right click on the @TC_Size pill on the size mark and go to edit table calculation:
- In Nested Calculation select @TC_Total_Sales
- In compute using select Specific dimension
- Make sure that Sub-Category and Path(bin) are both selected and sub category is on the top
- In Nested calculation select @TC_Percentage(Adjusted)
- In compute using select Specific Dimension
- Ensure the Sub Category and path(Bin) are both selected and Sub-Category is on the top.
- In Nested Calculation select @TC_Total_Sales
You will see the following
Now we will make the final adjustment and formatting:
- Hide the headers for X axis and Y axis
- Hide the grid line, zero, axis lines and borders
I hope you enjoyed this tutorial, and you can find this data visualisation on Tableau Public – Treemap chart