Tuesday, 24 February 2015

Messy heat map

My last blog post on heat maps was an attempt to persuade map-makers that the term actually means something other than what you might think it means...and that doing cluster analysis of some form or other on your data more than likely requires a better understanding of data and technique than a so-called heat map generator provides.

My Twitter feed lit up today as Manchester City played Barcelona in the Champions League Round of 16. Lionel Messi, the Barcelona forward, had a fine game by all accounts (to be fair he pretty much always does) and Squawka were on the ball with their live analysis during the game.

Squawka provide a web-based view of sport that collates and presents data as it happens. They tweeted the following:



Needless to say it brought on a nervous carto-twitch. If you read the previous blog you'll know by now that whatever the above is, it's not a 'heat map'. It's a density map of some form of cluster analysis but it illustrates far more than just another example of an inappropriately named map.

Here are some of the issues I see with this map and how similar issues are seen in almost all of these sorts of maps. They may help to understand that it isn't, in fact, a map of Messi leaking all over the pitch.

What is the data that was used?

Messi presumably ran about the pitch yet the splodges look like they are based on point data. Is this where he had the ball? Where he received the ball? Where he passed the ball to another player? Where he was stationary for a period or simply where he stood watching as Suarez scored the goals? Etc etc. While logic suggests that a map of Messi's running should be linear we are immediately confused in trying to decipher what this data actually represents because it looks like points that have been analysed to create a representation of clusters (more points = larger or more intense splodge). Without knowing what data the map represents we cannot decide whether he was all over the final third or not. If the data is indeed points then is that an appropriate metric and can it justifiably be used to show what they purport the map to be showing?

What are the fuzzy splodges?

The typical symbology on these sort of maps tends to go through some form of spectral colour scheme and this is no different. The hazy blue splodges are likely where less clustering occurred but is this a fleeting movement or pass or where he tripped over his laces? As Messi moves more or passes more (or whatever more) the intensity of the symbology increases. But what precisely does this represent? We have no legend to tell us what changes in colour mean and whether colour is mapped onto the clustering values linearly or logarithmically or...

Indeed - if you look at the overlap of two hazy blue splodges near the bottom centre of the map you'll notice that a simple overlap at the edge of two hazy blue splodges results in a bright, intense change in symbol. But if these hazy blue splodges are built from point data (presumably at the centre of the hazy blue splodge) then the overlap is simply an artifact of overlapping symbology...not necessarily overlapping data. These artifact overlaps occur everywhere on the map so it's unclear what the relationship is between data and symbology and how that then translates to Messi's actual movement or involvement.

The statement of being all over the final third also doesn't exactly stack up either. The main splodges are in a zone towards the top of the pitch graphic...a little left of centre but certainly not all in the final third. We'll assume Barcelona are attacking the left half of the pitch graphic and that even though teams switch sides at half-time the graphic maintains teams in the same half for mapping purposes.

All in all it's a graphic that reveals very little except gross error and uncertainty and which is utterly impossible to interpret in a way that reveals anything sensible about Messi's contribution to the game. 

These sort of back of an envelope 'heat maps' are unhelpful for any visual or analytic task. Quick to produce yes, but you can't make any sensible or quantifiable interpretation. Finally, we have no-one elses maps to look at so we simply have to presume that every other player's heat maps are in some way visually inferior to Messi's map.

Messy data. Messy clustering. Messy symbology. Messy map. Messy communication and very messy ability to interpret, compare or understand. Poor old Lionel Messi who is, quite literally, an innocent bystander in all of this...as the map, sort of, shows.

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.