
Visualizing hierarchical data using treemaps
Most data has natural hierarchies within it. So far, we've discussed Region, Sub Region, and Country. We used them on the scatter plot to allow the consumer of the visualization to navigate the different levels of the hierarchy, and group (or aggregate) the data at each level.
It's also possible to visualize the hierarchy directly using a treemap. A treemap is a hierarchical visualization and allows easy navigation up and down through the different levels and is the only Spotfire visualization, at the time of writing, that supports clicking up and down through the hierarchy on the visualization itself.
Let's create a treemap showing the relative infant mortality between the different Regions, Sub Regions, and Countries:
- Add a new page by clicking on the + sign at the bottom of the Spotfire window:

- Choose a treemap from the visualizations pullout:

Helpfully, Spotfire chooses the Region, Sub Region, Country hierarchy for the treemap. The defaults that are chosen for the other axes are a reasonable starting point too, but let's explore them in detail. Here's what you should see in Spotfire at this point:

The preceding screenshot shows the following elements:
- Hierarchy axis: This axis determines how to split up the data into the various blocks that you can see in the visualization. You can change how the blocks are shown by using the hierarchy slider, as per the scatter plot you created earlier on in this chapter. Experiment with the slider and see how it changes the display of the hierarchy and the detail it goes into.
- Size by axis: This axis determines the size of the blocks in the visualization. Spotfire has automatically chosen the column that estimates child mortality. However, the Sum aggregation is not correct:
- We need to change it to Avg. Please do this now, for both the Color by and Size by axes.
- Let's choose some more appropriate colors for the Color by axis, too. You may think that a gradient from red to green is a good idea, but I tend to find that red to green color schemes don't look very nice as the two colors clash badly. I usually prefer a darker shade of a color to represent something that is "bad" and a lighter shade of the same color to represent something that is "good":
- Click on the Max color icon on the legend and choose a color:

-
- Click on the Min color icon and choose another color. Spotfire will automatically apply a gradient to the colors.
- Although you won't be able to tell in the printed book (it's a grayscale book), I have chosen a dark brown to represent the Max and a light orange to represent the Min. You could, of course, get more creative with the colors by adding rules or points to the gradient—for example, to differentiate between above and below average regions, as per the earlier example in this chapter. If you want to do this, please right-click on the axis selector for the color axis (in the legend) and click Properties.
Now, let's explore the data a bit more by using the navigational aspects of the treemap:
- Each of the headings of the groups in the treemap are clickable. Try clicking on a header, for example, for Asia. The treemap will update, as follows:

- Note the treemap navigator at the top of the visualization. It is like a breadcrumb trail and will always show you where you are within the hierarchy. If you click All, you will be taken back to the highest level within the hierarchy.
- Of course, it's possible to change the level of detail shown on the hierarchy by changing the slider on the hierarchy axis, too. In this case, I have slid it all the way to the right in order to show sub-regions and countries:

There are a few things you need to know about treemaps:
- A treemap can be used as a source for a details visualization, so you can drill into the details of any of the sections of the treemap in your data if you have a large amount of structured, hierarchical data.
- A treemap is very useful for an at-a-glance view of the relative importance or weight of many categories of data. However, don't forget to provide another means of comparing the categories if you need to compare absolute values.
- A commonly asked question is—"Can I change the text in the boxes to show something other than the name of the category within the hierarchy?". The answer is "No"—I'm letting you know at this stage to save you time searching various online forums, and so on! However, I do know that TIBCO listens to customer requests, so later, if you feel this would be a useful addition to the Spotfire product, please submit an idea to the TIBCO ideas portal (or vote up an existing one). You can find the TIBCO ideas portal at https://ideas.tibco.com.