Piano Guidance
Photo by RF._.studio Pexels Logo Photo: RF._.studio

When should you not use a TreeMap?

For the reasons previously indicated, Treemaps are one of the visual elements most employed in Business Intelligence (BI) presentations, although they should not be used when the objective of the visualization is to make exact comparisons between the components of the dataset.

How do you stop missing notes on piano?
How do you stop missing notes on piano?

8 Tips to Stop Missing Notes on the Piano Practice scales to make your fingers more accurate. Practice triads and their inversions. Clean piano...

Read More »
What grade is an advanced pianist?
What grade is an advanced pianist?

Grade 3 is early intermediate. Grade 4 and 5 are intermediate levels. Grade 6 is late intermediate, Grade 7 is early advanced. Grade 8 is advanced....

Read More »

Treemaps, Why and How

Storytelling with Treemaps

Gradually but relentlessly, the number of files on the hard disks went from tens to hundreds, and from hundreds to thousands. Similarly, the number of folders and directories increased almost exponentially. It was essential to find some diagram that would allow a relatively simple way to visualize the contents of the new Leviathan. The solution came from the inventiveness of Ben Shneiderman, professor of Computer Science at the University of Maryland and creator of the Human-Computer Interaction Lab (HCIL). He was looking for “a compact visualization of directory tree structures” (#1). It was evident that the structure of the directories corresponded to a hierarchical tree scheme, but the existing diagrams were very bulky, and therefore inefficient. In his own words: “Tree structured node-link diagrams grew too large to be useful, so I explored ways to show a tree in a space-constrained layout” (#2). The final result was a diagram called Treemap. The unexpected was that its current applications greatly exceeded the original purpose. WHY: a Treemap is a rectangle-based visualization that allows you to represent a hierarchically-ordered (tree-structured) set of data. The conceptual idea is to compare quantities and show patterns of some hierarchical structure in a physically restricted space. For that purpose, rectangles of different sizes and colors are used to display the dataset from different perspectives. The goal is not to indicate the exact numerical values, but to “break” the dataset into its constituent parts and quickly identify its larger and smaller components.

Fig. 1: Treemap created with Plotly.

They are also used to indicate rankings, differences between parts, and relative proportions in non-hierarchical “flat” structures. In that sense, they are considered an alternative to traditional pie charts, which are often used to visualize “Part to Whole” relationships. The big difference with pie charts is that Treemaps allow you to compare the parts that make up the whole in a scheme of nested rectangles in a relatively small space. An advantage over pie charts is that they can include tens or hundreds of parts in a structure that may or may not be hierarchical. The efficient use of physical space and the intelligent color management make them an exceptional tool to visualize a significant volume of information in a wide variety of business analytical applications, as well as in financial, commercial, governmental, electoral, and similar fields: Standard and Poor’s 500 Index; Merval (Buenos Aires Stock Exchange); Election results by province or state; Exports by region, country or sector; Sales by product division; etc. The following Treemap shows Jamaica’s exports in 2017 separated by sector (agriculture, oil, chemicals, minerals, etc.) (#3).

Fig. 2: Jamaica exports in 2017. Source: commons.wikimedia.org (#3).

For the reasons previously indicated, Treemaps are one of the visual elements most employed in Business Intelligence (BI) presentations, although they should not be used when the objective of the visualization is to make exact comparisons between the components of the dataset. HOW: they are composed of a series of nested rectangles (tiles) whose areas are proportional to the data they represent. The larger rectangles (higher levels of the hierarchy) indicate the root or main branches of the data tree, and are subdivided into smaller rectangles that indicate the sizes of the nodes (lower levels of the hierarchy) that each branch of the tree has. The numerical values of the data set should be positive and correspond to the areas of the rectangles. An intelligent use of color allows new dimensions to be incorporated into the diagram. The usual procedure is to use color in the different rectangles to indicate a second categorical or quantitative value. Therefore, a ranking is indicated by the changes in the intensity of a single color; different positive and negative quantitative values are displayed by the changes in the intensity of two colors. The following diagram shows values over and below a threshold ranked with different intensities of two colors.

How hard is Grade 5 piano?
How hard is Grade 5 piano?

Grade 5 truly is bordering the intermediate to advanced level of piano playing and reaching this level is a massive triumph so you should take a...

Read More »
What is a sad song called?
What is a sad song called?

A mournful poem or piece of music composed or performed as a memorial to a dead person. dirge. lament. requiem. elegy.

Read More »

Fig. 3: Treemap created with Squarify.

From the above, it can be deduced that an appropriate use of color allows us to use Treemaps to represent losses, drops in sales, or other non-positive values. Always referred to a second quantitative value not represented by the area of the rectangle. The following Treemap shows the S&P 500 (#4). It is an index or collection of 500 widely held stocks on the New York Stock Exchange (NYSE) and NASDAQ. The size of the rectangles indicates the relative size of each company in the index. Different colors and different color intensities show graduations of positive, negative, and “neutral” results for a particular day: very bright red indicates a big shift downward, and very bright green indicates a big shift upwards. Undoubtedly, a Treemap is the most appropriate visualization for the enormous volume of the information displayed in that relatively small space.

Fig. 4: S&P 500 (#4).

Several algorithms allow you to display hierarchical data through nested figures in the shape of colored rectangles: Squarified, Slice and Dice, and Stripped. Squarified is the most implemented algorithm by commercial data visualization tools. It is based on a strategy that seeks to make each block as square as possible to facilitate comparison between them. It also tries to arrange the successive members of the data set (blocks, tiles) in a decreasing manner from the top left to the bottom right of the diagram. Finally, the algorithm has a good visual presentation on desktops, notebooks, and cell phones.

Some precautions to take into account when telling a story with Treemaps:

Always keep in mind that Treemaps are difficult to read as they rely on the audience’s ability to decode numerical information by comparing areas. Do not forget that humans are good at evaluating distances and bad at calculating areas. This drawback is amplified in a Treemap due to the large number of areas (rectangles, tiles) that are displayed on them. Before using a Treemap, it is essential to evaluate whether a bar chart or a pie chart does not tell the same story with less visual intensity. Do not forget that humans are good at evaluating distances and bad at calculating areas. This drawback is amplified in a Treemap due to the large number of areas (rectangles, tiles) that are displayed on them. Before using a Treemap, it is essential to evaluate whether a bar chart or a pie chart does not tell the same story with less visual intensity. These diagrams are not advisable when the really significant information has similar numerical values. In such cases, the algorithm generates blocks of very similar areas, difficult to compare in a dashboard. Treemaps cannot be used to display numerical variables that can take negative values such as losses. Remember that this type of restriction is common to all those charts that use areas to code the value of quantitative variables. Be very cautious if you want to use them in interactive presentations. Remember that if comparing areas is relatively difficult, comparing areas that change interactively is even more complicated.

Can you run out of air in an elevator?
Can you run out of air in an elevator?

You will run out of air if an elevator stops. Elevators are not airtight and suffocation in a stuck elevator is not going to happen. Nov 20, 2014

Read More »
How much of an age gap is OK?
How much of an age gap is OK?

Half-your-age-plus-seven"" rule An often-asserted rule of thumb to determine whether an age difference is socially acceptable holds that a person...

Read More »

Another issue that makes it difficult to make a good comparison is the absence of a common baseline, a drawback that bar charts do not have. It is generally not possible to include text in smaller rectangles when the differences in size between large and small blocks are very significant. The standard solution is to use tooltips to provide the information related to those rectangles when the user hovers over them. Of course, it is important to know Stephen Few’s opinion on the subject: “When conventional graphs, such as bar graphs, cannot be used because there are too many items to represent as bars in a single graph or even a series of graphs on a single screen, Treemaps solve the problem by making optimal use of screen space. Because they rely on pre-attentive attributes to encode values (area and color) that we can’t compare precisely, we reserve such methods for circumstances when other more precise visualizations cannot be used, or precision isn’t necessary.” (#5).

Drawing Treemaps with Python

As indicated by The Python Graph Gallery (#6), “the dataviz possibilities are quite poor”. To draw a Treemap with Python you must import the Squarify library (pip install squarify) and use the squarify.plot function indicating values, labels, colors, and transparency through the alpha attribute. The resulting diagrams are quite limited when compared to those generated by some commercial tools. A better alternative is to use Plotly through the treemap instruction whose syntax is much superior to its Squarify equivalent. In addition to indicating values, labels, and colors, the treemap syntax in plotly.express includes the path parameter, which allows you to define the hierarchy of the sectors from the root to the branches (#7). plotly.express.treemap(data_frame=None, names=None, values=None, parents=None, ids=None, path=None, color=None, color_continuous_scale=None, range_color=None, color_continuous_midpoint=None, color_discrete_sequence=None, color_discrete_map={}, hover_name=None, hover_data=None, custom_data=None, labels={}, title=None, template=None, width=None, height=None, branchvalues=None, maxdepth=None)

Conclusions

A Treemap diagram is an appropriate type of visualization when the data set is structured in a hierarchical order with a tree layout with roots, branches, and nodes. It allows us to show information about an important amount of data in a very efficient way in a limited space. The main purpose of the visualization is to make non-accurate comparisons between different levels of the hierarchy. They are also used for a “part of a whole” analysis with non-hierarchical data. They should not be used to draw accurate conclusions, with negative quantitative data, or when numerical differences do not allow for proper comparison.

If you find this article of interest, please read my previous (https://medium.com/@dar.wtz):

Mekko Charts, Why & How

Gauge & Bullet Charts, Why & How, Storytelling with Gauges

References

#1. — Ben Shneiderman (1992). “Tree visualization with tree-maps: 2-d space-filling approach”. ACM Transactions on Graphics. 11: 92–99. doi:10.1145/102377.115768. #2. — Ben Shneiderman, April 11, 2006, Discovering Business Intelligence Using Treemap Visualizations, http://www.perceptualedge.com/articles/b-eye/treemaps.pdf

#3. — https://commons.wikimedia.org/wiki/File:Jamaica_Export_Treemap.jpg

#4. — https://www.mergersandinquisitions.com/what-is-the-sp-500/

#5. — Stephen Few, 2009, “Now You See It: Simple Visualization Techniques for Quantitative Analysis“, Analytics Press; 1st edition (April 1, 2009)

#6. — https://python-graph-gallery.com/treemap/

#7. — https://plotly.com/python-api-reference/generated/plotly.express.treemap.html

Which came first piano or guitar?
Which came first piano or guitar?

Interesting fact: the guitar is actually much older than the piano. In the evolution of musical instruments, ancestors of the modern guitar can be...

Read More »
How much does it cost to tune an upright piano?
How much does it cost to tune an upright piano?

Typically, most piano tuners charge by the hour, but $100 to $200 every 6-12 months is much cheaper than having the piano restrung. This process...

Read More »
How rare is it to have A good singing voice?
How rare is it to have A good singing voice?

Perfect pitch is a rare talent, with less than 5 people in every 10,000 possessing the ability. It's thought that nature, nurture and environmental...

Read More »
Is there a free sheet music app?
Is there a free sheet music app?

MuseScore The next music sheet app we would like to highlight is MuseScore, which is primarily a music notation app for iPad, iPhone, Android, PC...

Read More »