Balanced treemaps

When Krzysztof Onak stopped by to comment on my last post about treemaps, he brought up an interesting nuance that I hadn’t considered. Instead of taking on a single tile at a time, recursing deeper into the hierarchy, I should try to take each level and pick it apart like a binary tree, trying to balance it at each step.

But that sounds kindof confusing, and I’m a visual kind of guy. Let’s look at each step.

The strip-based approach is the easiest. It’s generally pretty ugly, but it does at least preserve the order of the points. Quickly: (1) decide whether to divide horizontally or vertically, whichever is longer, then (2) cut strips/tiles for each point based on its percentage of the total area. Visually:

I’ve gone over squarified treemaps before, but quickly: (1) reorder your tiles from large to small, (2) choose to tile horizontally or vertically, (3) add tiles until the aspect ratio of the strip you are filling is the closest to square, (4) make a new strip and start over at 2.

There are arguments for and against squarified treemaps. If you have a flat dataset with no hierarchy or inherent order, then squarified treemaps are probably the way to go since they offer the easiest visual comparison between large and small items. You can also see the benefit of having all of the big stuff on one side and the small stuff on the other.

Of course, as order and hierarchy are destroyed, they may not be the best bet. Here’s the squarified version of that same dataset:

I’m still working toward some code for the circular-partitioned treemaps that I mentioned last time, but to get there I needed to step through two more variants.

Krzysztof’s point was that I should do this: (1) take my list of data points and split them as close to down the middle as possible, (2) make a cut to divide my rectangle according to that same ratio, and (3) keep doing this until I’d exhausted the entire list.


You can see that it’s conceptually close to the squarified version, and made many similar decisions, but with less distortion of the smaller tiles. But we’re back to having lost our order and hierarchy.

It took me a while, but I realized that you could do your best to retain the order of the tiles. It’s not going to be perfect, as you’re going from one dimension to two, but it’s close enough that you can get a much better feel for the original order:

Here, let me show you it next to the original strip-map:

Okay, almost done.

The other benefit of the balanced partition approach is that it becomes much easier to keep hierarchy visible in your dataset. Here’s a different dataset, this time with hierarchy:

Spiff, eh?

Now, there’s a reason I’m so hung up on treemaps lately. I’m getting to it, I swear. It’ll all become clear in the next week or so.