Creating beautiful maps with R

February 24, 2012
By

(This article was first published on Revolutions, and kindly contributed to R-bloggers)

Spanish R user and solar energy lecturer Oscar Perpiñán Lamigueiro has written a detailed three-part guide to creating beautiful maps and choropleths (maps color-coded with regional data) using the R language. Motivated by the desire to recreate this graphic from the New York Times, Oscar describes how he creates similar high-quality maps using R.

NYT immigration explorer

In Part 1, Oscar grabbed some voting data from Spanish elections and shapefiles (detailed map coordinates) from Spain's Official Statistics department (INE) and set to work in R. He then used the maptools package and lattice graphics to create this choropleth of voting patterns in Spain:

Part1
In Part 2, he uses the raster package to import pixel-based environmental data from NASA, to create a map that combines population density, land use and land cover in a single map. (Personally, I find it very difficult to interpret such multivariate maps encoded in multiple dimensions of color, but the process is interesting.)

Pop_landclass

Finally in Part 3, Oscar uses the pxR package to read map data in the PC-Axis format, and the gridSVG package to create an interactive SVG map. If you have a modern browser, you can click the image below, and then annotations will appear as move your mouse over the regions. [Updated: as Oscar explains in the blog, the annotiations require Javascript to work, so I've changed the image below to link to Oscar's annotated version.]

Map with annotations
With these examples, you can see how you can get close to the types of maps featured in the New York Times (which, themselves, often involve R in their production). You can find the data and R code used to create these maps at Oscar's blog linked below.

Omnia sunt Communia!: Maps with R (III)

To leave a comment for the author, please follow the link and comment on his blog: Revolutions.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: ,

Comments are closed.