Tuesday 17 February 2015

When is a heat map not a heat map

Actually, the answer to the question in the blog post title is most of the time...

The term 'heat map' has gatecrashed the cartographic lexicon. It has seemingly replaced other, more established, more accurate and perfectly good terms. It's used as a catch all for any map that portrays a density of point-based pieces of information as a surface. Here, I try and explain why I find it unhelpful.

Heat maps have become a popularist way to label a surface representation of data that occurs at discrete points. On one hand the search for a better way of showing point based data which avoids death by push-pin is a sound cartographic approach. Imagine simply looking at a map of points and trying to make sense of the patterns. Chief Clarence 'Clancy' Wiggum would certainly struggle to make sense of the pattern of crime in Springfield just from coloured dots.


It's difficult to process patterns of dots (other than more here, less there) and even harder when you're looking at thousands of dots that overlap (death by pushpin) so...let's make a heat map!

In analytical terms there's a number of ways one might approach the problem. One way is to bin your data into regularly shaped containers like hexagons, effectively a spatial summary of the point data. Another way is to interpolate lines of equal value across the map to create a surface which then helps us to see areas that display similarly high or low values across the map. Of course it's important to remember that any interpolated surface is effectively inventing data values for the areas on the map for which you don't have data or sample points. It's therefore important to think whether you want data making up for the areas between your data points when you know damn well nothing exists.

For instance, make a map of temperature and you'll likely use sample points. It's perfectly reasonable to infer that temperature exists everywhere as a continuous surface so filling in the voids where you have no data is fine. If, on the other hand, you have accident data for road intersections and you interpolate a surface it makes much less sense. Intersections do not exist across space so filling in the voids with made up data values is not really appropriate.

Let's assume Chief Clancy is making a surface based on some sensible logic. These interpolation methods collectively result in an isarithmic map. That is, the planimetric mapping of a real or interpolated three-dimensional surface. So Chief Clancy might see the pattern of crime in Springfield a little more like this (and before someone suggests the interpolation is a little off..yes, it's just for illustrative purposes. I'm a cartonerd but seriously...):


These sorts of isarithmic maps are used everywhere for displaying temperature (isotherm) to atmospheric pressure (isobar); and from height (isohypse) to population distribution (isopleth). They're also commonly, and erroneously,  referred to as heat maps.

Technically speaking, the map of crime activity points that Chief Clancy is looking at might be termed isometric data since it shows locations of discrete events that do not necessarily exhaust space. The fact that the dots are coloured actually suggests more than one incident. Rather than a simple interpolation of discrete points, he might instead do a kernel density analysis that uses the values at each point as a weighting factor to end up with a map like this:


His analysis needs to very carefully decide the shape and size of the kernel (search area) used to compare nearest neighbours. A small kernel will create a map that looks much like the original...just discrete points on the map but displayed as splodges. Choosing a kernel that is too large will create an over-smoothed, highly generalised map.

A more advanced version of kernel density analysis might be used to calculate a K function which constructs zones around events as a way of summing and weighting values which end up on the interpolated surface. It goes beyond simply looking at nearest neighbours and can help map patterns across a wider area. They're also commonly, and erroneously,  referred to as heat maps.

Hopefully Clancy knows what he is doing and not simply using a slider in a haphazard manner to achieve a map he likes the look of. There's nothing fundamentally wrong with sliders but it's also useful to know what the slider is doing to make what you're seeing.

If Chief Clancy is feeling particularly brave he may even fire up his favourite geo-analytical powerhouse and calculate the Getis-Ord Gi* statistic for the variable in question. The resulting p-values are mapped to show where statistically significant high or low clusters occur spatially.


This is often termed a hot spot map (again, sometimes referred to as heat maps) and which typically use red to show 'hot' areas (or a lot of something) and blue to show 'cold' areas (or much less of the thing in question). It doesn't show hot places and cold places and, frankly, if you don't use the right data inputs and know what it's mapping it can distort your view of reality beyond comprehension. It's a map of statistically significant clusters of data based on a multitude of decisions taken in setting the parameters. It's a complex but perfectly good analytical technique though the fact we're now beginning to see the introduction of terms that reflect 'heat' and, often, colours that connotate temperature, it begins to form a basis for misinterpretation.

These techniques form a valuable collection of related methods that create interpolated surfaces from discrete data points. They create isarithmic maps; predominantly isopleths because they map distributions of populations of some variable or another. Referring to them as a heat map is wrong because a heat map is something else entirely. Badging them as isarithmic maps is fine but it's important to recognise that they have very different data demands, functionality, complexity and potential and knowing these differences helps you understand and interpret the maps they create.

Just for the cartonerds, let's decipher the definition...an isopleth is a form of isarithmic map and shows change in the quantifiable variable over space. They differ from choropleth maps in that the data is not grouped into a pre-defined region (e.g. countries, census areas). They also work particularly well for data that exists continuously and which doesn't necessarily change at an abrupt point or a pre-defined boundary. In this sense, any surface of population based data that can be interpolated from point data is an isopleth. That's ISOPLETH from iso- Ancient Greek ἴσος (ísos, equal) +‎ Ancient Greek πλῆθος (plêthos, a great number)....or more easily understood as a map that shows equal numbers. The equal numbers being demarcated by isolines of equal value which divide areas which display similar characteristics.

So I've hopefully established that isarithmic maps are not heat maps but if we turn our attention to the use of descriptors and colours in such maps it helps to understand the misrepresentation a little more.

In all of the example maps Chief Clancy looked at earlier the colour schemes suited the analytical technique. The kernel density maps used single hue colour schemes which went from light to dark. The Getis-Ord Gi* map used a diverging scheme to show clusters of positive p-values (red) and clusters of negative p-values (blue)...though there's no particular reason why red to blue should be used other than to reinforce the use of terms such as 'hot' and 'cold'.

In all of these maps you can clearly see the areas that represent higher data values and the areas that represent lower data values. It's easy for us because darker shades are interpreted as 'more'. We describe patterns using terms such as 'more' or 'less' rather than 'hot' or 'cold' because that helps us understand the data using language that refers to quantities., 'With diverging colour schemes we naturally interpret the data as diverging away from a central value.  Again, 'more' and 'less' is useful as is 'statistically significant cluster' if we're referring to the result of the Getis-Ord Gi* statistic. Using heat related terms adds unnecessary confusion which is further compounded by the colour schemes often used for heat mapping.

The idea of showing heat using a rainbow colour scheme is likely based on the sort of colours you get when you 'see' something through an infra-red camera like so:


This technique is specifically designed to measure heat and display hot and cold areas so the use of reds and blues makes sense as it matches the data and the phenomena being mapped. It matches our cognitive ability to process what the colour actually represents. Greens in the middle are still odd though because it doesn't really suggest a mid-heat value. Sometimes these colour schemes avoid green altogether.

While this colour scheme arguably works when we're talking of temperature, when the 'mapped' phenomena is actually hotter or colder, transposing this colour scheme for any mapped data variable causes problems in our ability to cognitively process patterns like so:


Here, Chief Clancy is looking at a beautiful rainbow. Blues for colder areas, reds for warmer and yellow and white for, well, white hot areas. The middle is glowing white hot with progressively 'cooler' colours radiating out in a beautifully smoothed gradient. Springfield is on fire and the interpolated values appear to show a lovely linear gradient reflected by the colours. Does the data Clancy is working with vary spatially according to a linear distribution away from source locations? Linear rarely happens in reality so such maps can present a distorted view of what's going on with the underlying data.

More likely, such a map presents the results of an over-generalised cluster algorithm that has been combined with the application of a linear spectral colour ramp. Given the point of this blog post, it's not a heat map either...it's just a version of some form of density analysis that results in a surface that does away with isolines altogether and compounds the problems of interpretation by using an unhelpful colour scheme. It's averaged out the analysis and complicated the symbolisation which doesn't help the user task at hand. There's even some transparency thrown in for good measure to see a little of the basemap which also adds to the visual clutter. Of course,defaults can always be changed so let's not get too bogged down in colour choices though using spectral schemes to show quantitative data is never a good idea.

Clancy needs help but unfortunately the routine use of a red and blue diverging colour schemes and spectral colour schemes on such maps has become so ingrained in popular use that's he doesn't know it's not helping him understand the map particularly well. Why should more of something be 'hotter' and less of something be blue and 'colder'? We're talking about data here...not the weather, though given the dreadful use of colour schemes on weather maps it's unsurprising we've seen them re-purposed for the sort of maps people call heat maps.

Of course, if you move your heat map slider in a different way to define a different implementation of the cluster mapping method and choose different colours you may end up with this:


Or even this...


Different sized splodges with different colours that tickle your fancy. And all from the same data. What a cornucopia of colour that means, well... very little. And once you've made your data look like something and added some random colours...you can even animate it. Doh!

The key to understanding the utility of this type of map is having a good understanding of your data in the first place and choosing an appropriate technique and colour scheme to go with your analysis. While making these type of maps simply is helpful to many, it's also really important to support them in making better maps rather than in allowing them to fall into the trap of making basic mapping errors.

So, back to the main point... if none of the above are heat maps...and the misnomer has been reinforced through the use of poorly defined colour ramps...what exactly is a heat map? Does such a thing actually exist?

Yes...but strictly speaking it's not really a map; it's a visual representation of a data matrix.

A heat map has been around in statistical analysis for a good while. It's defines a graphical approach to code a matrix of data values into a graphical representation using colours. It's designed to reveal the hierarchy of row and column structure. Rows in the matrix are ordered so that similar rows are near each other and you see cluster trees on the axes. A heat map looks like this:



The closest spatial representation of data that might reasonably have similarities to a real heat map is a tree map...and that's a cartogram which has destroyed geography for the sake of creating an ordered matrix. At a stretch I understand why raster surfaces used to represent geography might be mistaken as heat maps because they are formed from a rectangular grid of pixels. But as I've set out here, I'd contest that the use of the mapping term isopleth already differentiates it from other map types and that we don't need to borrow a term from graph theory to simply replace one that already suits the technique. Proper heat maps go further than the mis-named cartographic versions anyway because the matrix is designed to illustrate correlations between variables through linked lines and other axis annotation.

Want to read more about real heat maps? Check out this rather good paper by Leland Wilkinson and Michael Friendly who explored the history of the term and of heat maps in 2008 (and from where the above illustration was sourced). It's prior art for heat maps in their true sense.

Tempted to make a heat map? I'd suggest doing a density analysis on your point data, experiment with different bandwidths (and understand what it is you're trying to map) and symbolize the resulting surface as an isopleth map using anything other than a rainbow or spectral colour scheme. If you're using a slider and default colours...think about what the slider is doing. Use it sensibly and try and understand how it's interpolating your data and, if you can...change the bloody colours from a rainbow palette! If you can't, then maybe try a different map type altogether.

More generally, I find that the introduction of replacement terminology where perfectly good terms already exists creates a further division between what we might call professional cartography and the wider world of map-making. I'd prefer to see those worlds come together under the same umbrella and for a better understanding to emerge through the use of a standard and accurate nomenclature. We don't need to dumb down mapping or how we talk about it to encourage better mapping.

PS - with resspect and apologies to The Simpsons whose image I have used and abused in this post.

2 comments:

  1. Nice analysis Kenneth. I'm not sure however the hierarchical tree argued by Wilkinson (reflected in Wikipedia's heat map page) is really a robust defining feature worth defending. There seems to me no strong argument for why a variable MUST have a hierarchical structure. Plus we see 'heat maps' all the time with continuous/discrete variables of no defined hierarchy - Alberto Cairo noted these excellent examples just the other day: http://www.thefunctionalart.com/2015/02/on-power-of-clear-visualizations.html. It makes more sense to me to take a more inclusive definition and specify as 'hierarchical' when necessary to distinguish.

    To be my own devil's advicate however, if hierarchy criterion is loosened it seems to me ANY spatial raster dataset (with cell values represented by coloured tiles) can legitimately be classified as a 'heat map' - just one with axes of spatial coordinates instead of statistical variables. But this of course gives 'map' a double meaning, which just sows confusion. All in all, while I share your distaste for dumbing down, I do slightly wonder about the term's sustainability in this age of the internet map mash-up..

    ReplyDelete
  2. Thanks for the comments. I don't disagree. Spatial coordinates, of course, bring their own hierarchy but not necessarily a matrix that makes sense unless you know the mapped variable varies spatially because of location e.g. northern places have a particular character that differs to southern. You're right that in many ways its the loosening of criterion that perhaps causes techniques to be grouped under a sexy catch-all label and yes, the map mashup and search for the single 'make map' button is really at the heart of much of this.

    ReplyDelete