Working with shapefiles, projections and world maps in ggplot
In this post I will show some different examples of how to work with map
projections and how to plot the maps using
ggplot. Many maps that are
shown using their default projection are in the longlat-format, which is
far from optimal. For plotting world maps I prefer to use either
Robinson or Winkel Tripel projection—but many more are available—and I
will show how to use both these projections.
Before we get started you need to download a couple of shapefiles that we will use. You can find them here:
Put them directly inside your working directory. We will use functions
rgdal-package to read the shapefiles into R, so if you do not
have it, you need to install it before you continue.
This will create a longlat-projected world map.
Here the world map is shown using the Robinson projection.
However, the Caspian sea is missing. This is because of how ggplot handles polygon holes. Ggplot will plot polygon holes as a separate polygon, thus we need to make it pseudo-transparent by changing its fill color.
![World map in ggplot2 polygon hole example][./img/map3.png]
Now the Caspian sea is visible.
If we want we can also add a graticule and a bounding box. The bounding box is useful if we want to make the sea blue—especially when using some form of curved projection. Here I have added a graticule and bounding box to the longlat-map.
Robinson projection with added graticule and bounding box.
Here I have added country borders to the previous map plot.
Bubble plots are a popular way of displaying information on maps. Here I used project() to reproject the bubbles’ coordinates into the Robinson projection.
Lastly, here is an example of the Winkel tripel projection. This
projection became popular after 1998 when the National Geographic
Society choose to use it for their world maps—using it to replace the
Robinson projection, which they previously used.
Published May 23, 2013 (View on GitHub)