TreeMap Viz

Data Viz
TreeMap
Author

Tim Anderson

Published

September 16, 2020

TreeMap Visualizations: An Overview


A TreeMap is a type of data visualization that represents hierarchical data using nested rectangles. Each rectangle (or “tile”) represents a category or a sub-category, and its size is proportional to a specific quantitative value. This visualization is particularly useful for displaying relationships between parts of a whole and spotting patterns, proportions, or outliers within complex datasets.

About the time I was in grad school, the folks at SmartMoney.com popularized this visualization technique. TreeMaps are a great way to quickly visualize the relative sizes of different items. Tableau makes it very easy to create interactive TreeMaps to dig down into the data.

I like to use this charts to look at everything from brand shares to product segmentation. TreeMaps aren’t for everyone, and I’ve found that if you show them to an audience they often can cause more questions than they are worth…but for basic data exploration and trying to better understand relationships between entities they work for me.

Here is a quick example of how one might compare unit brand shares for a certain market.

suppressMessages(library(tidyverse))
suppressMessages(library(treemapify))
suppressMessages(library(janitor))
suppressMessages(library(scales))


# Old Projector Market Data:
df <- suppressMessages(clean_names(read_csv("pma2013_census.csv")))

# Just going to look at 2013
df <- df %>%
     mutate(year = as.numeric(substr(year_qtr, 1, 4))) %>%
     filter(year == 2013) %>%
     filter(brand != "zOther")
chart_colors_qualitative <- c("#e41a1c", "#377eb8", "#4daf4a")




df %>%
  filter(country == "United States") %>%
  group_by(technology, brand) %>%
  summarize(vol = sum(units_sold))  %>%
     
       ggplot(aes(area = vol, label=brand, fill=technology, subgroup = technology)) +
  
          geom_treemap(color = "white", size = 1 , alpha = 1) +
  
          geom_treemap_text(aes(label = brand) , color = "white", size = 14 , fontface = "bold") +
     
          geom_treemap_text(aes(label = comma(vol)), 
                            size = 12 , color = "white", place = "topleft" , padding.y = grid::unit(18, "points"))+
  
          geom_treemap_text(aes(label = percent(vol/sum(vol),  accuracy = .1)), 
                            size = 12 , color = "white", place = "topleft" , padding.y = grid::unit(32, "points"))+

          geom_treemap_subgroup_border(color = "white", size = 2) + 
          
          geom_treemap_subgroup_text(aes(label = comma(sum(vol), scale = .000001, suffix = " M", accuracy = .1)),
                            color = "white", grow = FALSE , size = 18, place = "bottomleft",  fontface = "bold", alpha = 0.7) +     
     
          theme(legend.position = "none") +
          labs(title = "2013 US Projector Unit Sales by Brand and Imaging Technology") +
          scale_fill_manual(values = chart_colors_qualitative)         
`summarise()` has grouped output by 'technology'. You can override using the
`.groups` argument.
Warning in geom_treemap_subgroup_text(aes(label = comma(sum(vol), scale =
1e-06, : Ignoring unknown aesthetics: label

Key Features of TreeMaps

  1. Hierarchical Data Representation:
    TreeMaps display hierarchical (parent-child) relationships. The parent category is represented as a larger rectangle containing smaller rectangles for its sub-categories.

  2. Size Indicates Magnitude:
    The area of each rectangle is proportional to the value it represents. For example, larger sales figures for a product category result in a larger rectangle.

  3. Color for Additional Insights:
    TreeMaps often use color gradients or distinct hues to represent a second dimension of data, such as performance metrics, trends, or categorical groupings. For example:

    • A gradient might show profit margins (e.g., red for losses, green for profits).

    • Distinct colors might separate product categories.

  4. Compactness:
    TreeMaps are highly space-efficient, making them ideal for comparing proportions when screen real estate is limited.

  5. Interactivity (Optional):
    In digital platforms, TreeMaps can include interactive elements like tooltips, zooming, or filtering to explore specific parts of the hierarchy.


When to Use TreeMaps

TreeMaps are ideal for:

  • Part-to-Whole Relationships: Understanding how categories contribute to a total.

    • Example: Revenue breakdown by product category in a business.
  • Comparing Categories: Visualizing differences in size between hierarchical categories.

    • Example: Market share distribution among competitors.
  • Spotting Outliers: Quickly identifying large or small values within the hierarchy.

    • Example: Expenses by department to find unusually high costs.
  • Maximizing Space: Presenting data concisely when space is a constraint.


Advantages

  • Visualizes Complex Hierarchies: Helps viewers grasp relationships within large datasets quickly.

  • Space-Efficient: Fits a large amount of data into a single, compact view.

  • Customizable: Color and interactivity can convey additional dimensions of data.


Limitations

  1. Label Visibility:
    If the rectangles become too small (due to data granularity), labels can be hard to read.

  2. Overlapping or Dense Data:
    For very dense data, the visualization can become cluttered and lose clarity.

  3. Not Ideal for Trends:
    TreeMaps do not show temporal trends or continuous data changes over time.

  4. Size vs. Proportion Confusion:
    The size of rectangles may lead to misinterpretation if the proportional context isn’t clear.


Best Practices for TreeMaps

  1. Keep Hierarchies Simple: Avoid too many nested levels, as they can become visually overwhelming.

  2. Use Distinct Colors: Use color coding effectively to differentiate categories or highlight important values.

  3. Provide Context: Include titles, legends, and tooltips to help viewers understand the data.

  4. Avoid Overloading with Data: Focus on the most relevant categories or summarize smaller categories into an “Other” group.