Saturday, 9 August 2014

Web Mercator and Comparisons

Getting the curved surface of the earth onto a flat map (paper or screen) requires a map projection. The reason so many projections exist is because there is no perfect projection and they all contain distortions which affect area, distance, shape or size...and distortions vary to different extents across the map.

While for most people, the often complex mathematics of transforming locations to the map is beyond their expertise it's important to pay some attention to the choice of projection. Choosing an appropriate projection is vital to ensure that the inherent distortions don't wreck the very purpose of your map.

Let's look at one example...say, for instance, you were wanting to create a map which allowed you to compare the areal extents of different cities across the world. You might want to see how one city compares to another in terms of the amount of green space, or the population density in urban areas. The one thing, the only thing, you need to get right is the choice of a projection that supports visual comparison. You need a projection that does not distort area...because area is the one property of the map that supports the cognitive process of visual comparison. Let's see this in action...

We can see what happens to distortions when we overlay Tissot's Indicatrix on the curved surface of the earth. The Indicatrix is simply a grid of equally sized circles (on the globe) which are a very familiar shape which makes it easy for us to see what happens when it gets distorted through projection. When projected, the grid of circles of equal size, shape and area are distorted which gives us a clear indication of what happens to the real geography that gets projected at the same time.

Tissot's Indicatrix on a globe:


Here's what happens when we project to Web Mercator, the default for web maps:


Web Mercator preserves angles (which is why the circles retain their shape) but distorts size, and, fundamentally, area. It's great for navigation (its intended purpose) but dreadful for most other purposes.

Now let's compare the two cities marked on the map...Oslo and Singapore.

Oslo is at 60 degrees North. Singapore is pretty much on the Equator at 1 degree North. There's virtually 60 degrees of latitude between them and looking at the two Tissot Indicatrix circles they fall in you can see the distortions that Web Mercator creates in the size of area between the two places. If you examine the size of the two circles you find that the Indicatrix around Oslo is approximately 75% larger than the one around Singapore.

Let's have a look at the impact on a real map. The following maps are on Web Mercator and both at a scale of 1:250,000. Oslo on the left, Singapore on the right.




Now let's look at exactly the same map but projected using a Cylindrical Equal Area projection. I've switched the standard parallel to 60 degrees North for the Oslo map just to ensure the shape isn't distorted compared to Singapore but areas are consistent between the two maps. Now compare Oslo with Singapore.



Oslo is now shown at the correct areal extent and size compared to Singapore. The distortions you see in the size of text etc is simply because the map tiles used to display this were originally in Web Mercator...so the fact they are now reduced in area by about 75% actually results in the map looking like it's shrunk. It has! It also shows how much Web Mercator tiles are distorted in terms of area the further from the equator you go.

The answer...pick the right projection for the right job. You can go beyond Web Mercator on a web map so it's just a case of figuring out how to do it using your technology of choice. If you're going to be comparing areas either for city comparison or for thematics you really do need an equal area projection unless all of your cities sit on the same degree of latitude. If not, you're literally pulling the wool over the eyes of your map readers and they leave with a totally distorted impression of the themes mapped.

Next time you look at a map whose purpose is comparing places just pause to check the projection and then make your own decision whether you can trust what your eyes are telling you.


Friday, 8 August 2014

Three dee thematics

I've always been intrigued by the potential for 3D in thematic cartography but it is that much harder to get 'right' than 2D...and look at what a mess many get in when trying to make even the most basic of 2D maps.

We see the world in three dimensions because we were given two eyes and stereoscopic vision. That gives us depth perception. In making maps on a flat surface (paper/screen) to mimic how we see the world we have to go beyond our basic palette of visual variables and symbol encoding and play with additional variables. We have to make the eyes see the third dimension.

The standard way of achieving that is to make the map in a perspective view...near things are closer to the eye than further away things. We can accentuate this by perhaps adding a sky in the background (to mimic a far off horizon) or add in haze to diminish objects further away in the same way as haze affects our view in reality. This generally works well for maps of the natural world....mountainscapes and street scenes for instance.

But this approach doesn't apply equally for thematics because the principle objective is to create a consistent view to support comparisons across the map. The perspective view does not support that cognitive need.

Take the following example in which the Obama/Romney 2012 percentage share of vote election results are shown using a diverging hue colour scheme. Increasingly blue = Obama, Increasingly red = Romney. purple = equal share.



What the map doesn't show us is how many voters there are in each county which might help us better understand the reason Obama won...so let's whip it into 3D and use extruded areas to show the number of voters.



Simply placing the choropleth on a virtual globe and extruding areas is a very common approach to 3D thematic mapping but it's bloody awful!

The perspective view seriously compromises our ability to compare the height of our extrusions like-for-like. The foreground is nearer the eye than the background. Worse, the curvature on a virtual globe alters the shapes as well so we're seeing all sorts of distortions that our brains have no hope of disentangling. The “fish eye lens” effect mean each prism is viewed from a different angle than its neighbors, making comparison just a little bit harder as we have to mentally account for these differences in our estimates. It's hard to judge the height of something when you are staring directly down at it too...look at those areas in Florida. This matters because height is the visual variable that does the “work” in this map—it’s how the data are encoded visually.

Here are a couple of other examples that make the same mistake. First up, capacity by energy source in the US:

The map tells us (yes, it does...in the blurb at the top) that we're seeing a clear stratification of energy sources across the US. Are we? I just see a map whose visual centre is focused on the sparse areas in the middle (the least interesting datawise) and a load of 3D columns of various colours fading off and disappearing over the horizon. It's like the data is running away, off the edge of the map, scared to be party to the horrific map it's been placed on.

In this example, 3D kills the map. The intent to 'look cool' by using a curved virtual globe destroys any hope of the reader being able to see any patterns. Look at the large orange bar in Arizona toward the front...is it taller or shorter than the one you see poking out above the skyline in the north-east? Who knows...but I bet they're about the same value. And stacking colours on top of one another makes the top colours more prominent anyway. Who knows what's hidden from view in the east. And finally, what of the colours...nearly 30 of them. The map reader has no hope of figuring out the difference between distillate fuel oil and petroleum gas...or geothermal and purchased steam.

Another I saw recently appeared on a T-Mobile advert:


 The title is meaningless. The legend shows us T-Mobile's data network usage in the slightly darker pink among their partner networks in slightly lighter pink. OK - it's an advert. The point is to show complete nationwide coverage and they wanted something a little more visually striking than a choropleth so...threedee it! Except compacting the map by putting it on its side and tilting it so dramatically makes it impossible to see where all those columns actually sit. And what's the vertical scale? It seems that the base height is actually extruded a fair bit to give the impression that perhaps even a small usage/coverage is a little larger than it might actually be. The map is designed to obfuscate reality because it's an advert...but if we wanted to make sense of the actual distribution the 3D approach kills it.

And here's an example from Andrew Hill which you really have to see as the web map here to fully appreciate its full three dee gory glory:


Andrew does some great work and pushes what technology allows. He also brings a fresh perspective on making maps that pushes the boundaries and challenges long-held principles. That's great in many ways but there also has to be a sense of understanding when the outcome doesn't stack up cognitively.

The hexagons have been used to bin the point data (911 calls) and height of the prism relates to quantity. All well and good to this point...but try and compare height relative to an absolute vale or relative to one another and you quickly become disoriented. Technically this is cool, no doubt. Cartographically it's questionable...very questionable, because it doesn't support the necessary cognitive processing needed to understand the pattern.

I did enjoy his twitter banter though...



So can we make better 3D thematic maps? Yes. You simply need to use an isometric projection which distorts the plane on which your map sits to make the scale equivalent across the whole map. Here's the election data on an isometric base:


Now unless you're going to provide the ability to rotate and interact with the map, you're going to still suffer the problems of occluded data but at least here each column is in the correct relative proportion to one another. We can accurately compare heights across the map and make sensible inferences. The interactive version is here which supports rotate, pan and zoom...though be warned that another difficulty with interactive maps is the constant ability to rotate, pan and zoom means we lose track of our visual anchors and this generates short-term memory flushing. In other words...you easily forget what you just saw and that means you lose the ability to build a comparative picture.



There we go...some thoughts on threedee thematics. In short...stick to 2D unless you're prepared to go the extra distance to deal with the additional problems 3D creates.

The reason for cartography

If ever there existed a reason for cartography then this is it. Possibly the year's worst map so far.


It was on the New Republic web site today as a map to accompany a story by Jonathan Cohn.

There is nothing about the map that is correct...actually, that's a lie...the projection (Albers equal area) is correct. The data, however needs to be classified, it needs to be normalised and it needs a sensible, sequential colour scheme.

To be fair to the guy he's taken some serious social media heat and redrawn the map. The data is now classified and he's got a decent shading scheme. Still not normalised though...so it's impossible to make any sensible visual comparisons.



Is the availability of tools to allow anyone to make maps a good thing. Yes...as long as those same people appreciate that if they are going to do so they are obliged to learn how to avoid the basic mistakes as a bare minimum. Cartography exists to guide people. Yes, there are basic cartographic rules but they are designed to tell map-makers how people read maps and, therefore, how to design them to make sense and be useful. If you're going to make a map of your data, ignore cartography at your peril.

And as I type...Steve Koczela has re-worked the data into per capita so here is a 'correctly constructed' map. Good projection...classified sensibly, decent shading scheme...and normalised data so we can compare like-for-like across the map. All rise!


So there you go...the first map shouted Pennsylvania and Alaska (bright colour catches the eye). The second map told me Texas and Florida were screwed (darker colours = more). The final map...Mississippi by some margin from North Carolina. Texas isn't that bad after all.

Finally...a small parting shot...with about half the states missing data...maybe this would look far better as a bar graph anyway?


UPDATE: Cohn has updated his web page to include a per capita map. As this blog is set up entirely to point out cartographic mistakes (often with a little of my cursed British humour thrown in which I know isn't to everyone's taste) it's a welcome sight to see people respond and correct their efforts where necessary. I admire Cohn for taking the views of this commentator, along with many others, into account and correcting his mistakes. It's encouraging that some actually do want to learn and move forward with their work. There's also a nice write-up of the need for constructive critisism spurred on by this map over on Alberto Cairo's excellent blog.


Friday, 13 June 2014

Pedantic cartography

As regular readers know, this entire blog is set up to fight the fight against cartofails. It's written in a jocular style with my British sense of dry humour. I was born with it. It's just the way we're built. Where I can I provide clarification on why a particular map fails and how it can be improved. Occasionally I even re-work stuff to show a 'better' alternative. Remember, this blog began with my correction of the True Size of Africa cartofail by Kai Krausse and my very first blog post.

I recently did a reworking to show where The Proclaimers may have reached in 500 miles. Over the last few weeks it's picked up quite a head of steam and been featured in Slate, The Atlantic's Citylab, got to Number 1 on the Reddit Mapporn sub-Reddit and even warranted a post by that most nonsensical Twitter account @Amazing_Maps. And today it again popped up in The Telegraph...once a respected, though very right wing, British newspaper. All terribly prestigious coverage for what must rate as my most frivolous mapping project ever.

This latest effort by James Edgar has me wincing and has my friends and colleagues chortling into their corn flakes. Edgar has reworked the story from a collage of other sites and it shows. I'm introduced as a pedantic cartographer. Yeah yeah, maybe that's true but why is it that virtually every cartographer get's labelled as pedantic, picky or awkward as if it's a fundamental flaw in our character? These labels stick and really don't help the cause. It's like every scientist has to be a boffin or, dare I say, every journalist is accused of lazy journalism. Actually yes...that's exactly the point. Lazy journalism.

How does correcting a common mapping error by making the effort to show and explain the error with the intent of improving people's appreciation of maps become something to deride? Pedantry is an obsession with 'minor rules'. Sorry pal, but these minor rules actually become very important in mapping even if you neither care nor know about it.

It's not about precision as Edgar suggests...I was not making a more precise map...I was making a correct map for the projection used (Web Mercator). Apparently I "created an accurate projection". No...I did no such thing, the projection already exists. What I did was map correctly on top of it. He goes on that I explained that "simply drawing perfect circles around the start point on a flat world map would not offer a true indication of where they could get to". Actually I didn't say that. You can draw perfect circles on any flat map that uses a conformal projection. You cannot on Web Mercator (actually, strictly speaking you can...they just won't be perfect circles when projected back onto a spherical surface). It's a function of the mathematical projection, not the fact the map is flat. Apparently I then used a "clever computer tool called a Web Mercator". Seriously? Did you not even use Google to check Wikipedia to find out what Web Mercator actually is?

Comments are not enabled on Edgar's post so I have no right of reply. He didn't contact me before running the story so i cannot even claim I've been misquoted.

Let me finish off with some true pedantry. Edgar refers to me as Mr Field. It's actually Dr. Yeah, that's pedantic but heck...I have a qualification in my area of expertise.

The Telegraph? Wow...more like the Daily Mail.