R: simple world map (Robinson, ggplot)

map_draft_1

Robinson projection seems a bit tricky to work with while using ggplot() in R. At least, at the time of this posting (Dec 2016) I could not find a smooth working solution with coord_map() as discussed here. However, I came across a post of Bob Rudis where he proposes coord_proj() which should do what coord_map does but using proj4::project instead of mapproject. It seems that coord_proj is not implemented in ggplot2. Nevertheless, Bob Rudis explains at the end of his post how to integrate it locally in ggplot2; or, use his package ggalt (though that failed for some updating reasons in ggplot2).

All in all, a general work around is to project everything outside of ggplot with rgdal::spTransform() function. Theoretically, this way should allow for any projection. A bit of care should be given to graticules and their labels as well. Helpful was this link and this SO link. Nevertheless, there are many more interesting projections out there – check this Wikipedia page for some examples and proj4.org for their PROJ.4 strings.

Below is some code example. Of course, things can be done in different ways and below is one perspective. Also some of the code below was helpful for creating this figure in Bennett, Joanne M., et al. “GlobTherm, a global database on thermal tolerances for aquatic and terrestrial organisms.” Scientific data 5 (2018): 180022.

Creating the graticule labels data.frames (lbl.Y & lbl.X) used in the code above can be done with:

Downloading data from www.naturalearthdata.com can be done as fallows: (update August 7, 2017: you might want to check the package rnaturalearth)

 

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s