Sometimes people send me questions about how to work with custom map projections in Tableau. For instance, Alan Eldridge asked me about working with polar ice data. Or, sometimes I get questions about making a US map with Alaska and Hawaii in a little inset in the corner of your map – without needing to use three worksheets, or how to make a map of Canada that is in the Lambert Conformal Conic projection (the most common projection used at Statistics Canada) instead of Web Mercator... It turns out that all of these things are possible in Tableau:
Since working with map projections is a pretty big topic, and something that I like quite a bit, I’ve written up a few blog posts on it. I’ve broken them into two parts: map projection basics and data manipulation for Tableau. The two parts should stand alone, so if you want more background about what is going on under the hood, you can start here with Part I (map projection basics), and if you don’t care about the basic mappy science that goes behind the fun tricks, you can just jump to Part II (data manipulation).
Since we have a lot to cover, let’s get rolling and go through enough projection basics (in general) for you to be dangerous be creative with map projections in your visualizations.
While I’ll give a brief overview of what happens in the projection process, I’m going to focus on a small set of topics important to working with alternate map projections in Tableau. For more in-depth discussion of projections, I recommend:
- daan Strebe’s ‘Map Projection Essentials’ (daan is a Senior Software Engineer here at Tableau).
- The Wikipedia entry for map projections is also fairly comprehensive
What is a map projection?
Map projection is the process of transforming angular (e.g., latitude and longitude) coordinates into planar coordinates. The projection is just a mathematical definition of how we go from the angles (spherical or geographic coordinate system) into a planar, projected coordinate system (the good ol’ Cartesian coordinates that you might remember from elementary school).
The fun maddening part of map projections is that whenever we do this transformation from 3-dimensional angular coordinates to 2-dimensional planar coordinates we introduce distortion in the form of one or more of the following: shapes, areas, angles, and distances…and just to make things more fun with distortion, know that it’s impossible to preserve both areas and angles on the same flat map!
Why do we have these distortion problems to deal with? I find that an easy way to think about this is to peel the skin off an orange. Is there any way to remove the skin and end up with a completely flat, un-torn, un-mangled peel? Even if you can manage a one-piece skin that looks pretty flat when you squish it down do you think it would look good as a map? Probably not. See my attempts:
To bring that back to the map, think of a map projection as the mathematical warping, stretching, tearing, and stitching back together of the orange peel / Earth surface. There are infinite ways of doing this, so the possibilities are endless with respect to what your final map looks like. For instance:
When making maps, a good cartographer will try to do two things: 1) minimize distortions so that their map is as accurate as possible for the location being mapped and the purpose of the map (e.g., do you need to take angular measurements? Are distances really important? Are relative areas really important?), and 2) make the map look nice.
Equal area projections with two different looks…I like one more than the other…
Most geopolitical entities (countries, states, provinces, counties, etc.) will have specific projections suggested for use in order to minimize the distortion in that area. It’s common to see the same general projection used in different locations, but with slight modifications to the parameters of the projection to tailor it to the location. Here is a Lambert Conformal Conic a central meridian of 0° and standard parallels at 20° and 50°:
For regional data, you might find Canadian data in this very same Lambert conformal conic map projection, but with standard parallels at 49° and 77° and with a central meridian of 91° 52’ W (Statistics Canada details here; image on the left below), while for the conterminous United States (the ‘lower 48’), you might see the same projection used, but with standard parallels of 33° and 45° and a central meridian of 96° W (image on the right below). They are similar, but not the same – look at the stretching in the far north for a good visual indicator.
Or, consider them arranged on top of one another. The projection with the parameters set to optimize for Canada are in orange, and for the US are in blue:
While cartographers typically like to pick different projections based on the location they are mapping, in many general purpose, non-geographic information system (GIS) mapping tools, there is only one projection to choose from and that one projection has to work for mapping local-scale (e.g., city), global-scale, and everything in-between. This projection is Web Mercator. I will use this particular projection as the example moving forward to explain the basic principles behind bringing your projected spatial data into Tableau.
Well, hello Web Mercator. It’s nice to meet you!
Tableau uses the Web Mercator map projection for mapping; this is the same map projection that you’ll see in pretty much every web mapping service (Google Maps, Yahoo Maps, etc.). While some people have strong negative opinions of this projection due to the distortion in the high latitude regions, for better or worse, it has become the standard for online mapping.
Why is this particular map projection so popular?? Most map services are designed for mapping from local to global scale – and we have to pick a single projection to work with, nothing will be optimal and this projection has some benefits, like:
- it’s rectangular so it is easy to chop into the individual little map tiles that nest inside each other for viewing at different scales,
- the math behind it is simple and quick,
- because it is a rectangular projection, North is always the same direction (typically the top of the map), and
- because it is (nearly) conformal (preserves angles on the map), for local-scale mapping we don’t see things like distortions of the angles at which roads intersect. There are some other reasons, and if you are really a glutton for map projection punishment, I can recommend a bit of reading that you might enjoy (Implications of Web Mercator and its use in online mapping)
Now let’s get to the fun stuff – what do you need to master if you want to make maps in Tableau that are not displayed in Web Mercator coordinates? It’s really just remembering a simple property of map projections – that the projected coordinates are just one big Cartesian coordinate system, and that in order to draw your geographic data, the system (Tableau, a GIS, whatever) displaying your data doesn’t care what projection you are using, it just wants to know what the x&y coordinates for every vertex in your data and then each vertex is dropped onto the right spot on the Cartesian coordinate system.
What does that mean to you? It means that you get a big blank ‘canvas’ on which you can draw your data, and so long as your data set’s coordinates are within the right range (and your coordinates think they are in the same coordinate system as our base map, Web Mercator), you should be able to drop any polygons you want onto the map. Here is what that map ‘canvas’ looks like in Tableau with our Web Mercator base map underneath:
Take, for example, the coordinates for the conterminous United States (‘lower 48 states’)….here is the same dataset in a few different map projections – note the differences in shapes and bounding box coordinates listed for each:
You should be able to see in the bounding box coordinates that they would each draw in different locations on our ‘canvas,’ but let’s go ahead and throw them all into a Tableau base map to see where they fall. Before we do this, think back to our graphic of the coordinate system that we’re working with, take a look at the bounding boxes listed above for each of the datasets (in projected coordinates), and imagine where they will fall on the map. Then keep reading to see if they line up with what you expected.
Plate Carrée – when zoomed to the extent of the data it looks just as expected.
But when we zoom out, something strange happens…our states disappear! Why? Think about where data with this bounding box falls in a coordinate system that runs from -20mil to +20mil:
xMin, yMin (-124.7, 24.9)
xMax, yMax (-66.9, 49.4)
Yes, it becomes a super-tiny set of polygons right around 0,0.
Web Mercator – it shows up in the right place…because the coordinates are just right for dropping that US shape on top of the US in our Web Mercator base map
Albers Equal Area - looks good, but totally in the wrong place! Why? Because this particular variant of the Albers projection was tailored to be centered on the US, which puts 0,0 right in the middle of the US.
The big so-what…
Map projections just define the translation from angular to planar coordinates. Once your data is in planar coordinates, so long as the range on those coordinates fits inside the extent of our Web Mercator map tiles, you can put any data you want onto the map. But…as you can see above, the Tableau base map tiles may not provide quite the right context underneath your map data.
In my next post, I’ll go through an example of how to adjust projections on your spatial datasets and bring them into Tableau.