The maps library for R is a powerful tool for creating maps of countries and regions of the world. For example, you can create a map of the USA and its states in just three lines of code:
library(maps)
map("state", interior = FALSE)
map("state", boundary = FALSE, col="gray", add = TRUE)
The coordinate system of the graph is latitude and longitude, so it's easy to overlay other spatial data on this map.
Unfortunately, the data for the maps library isn't sufficient for some applications. The maps themselves are fairly low-resolution (although higher-resolution data is available in the mapdata package), and political boundaries can be incomplete or out-of-date. Luckily, there are now free online resources where you can find updated map data for use with R.
GADM is a spatial database of the location of the world's administrative boundaries, and as Claudia Engel discovered the map information is available as native R objects that can be plotted directly with the spplot function (from the sp package). For example, here's how to load the data for Switzerland, and then plot each canton with a color denoting its primary language:
library(sp)
con <- url("http://gadm.org/data/rda/CHE_adm1.RData")
print(load(con))
close(con)
language <- c("german", "german", "german","german",
"german","german","french", "french",
"german","german","french", "french",
"german", "french","german","german",
"german","german","german", "german",
"german","italian","german","french",
"french","german","german")
gadm$language <- as.factor(language)
col = rainbow(length(levels(gadm$language)))
spplot(gadm, "language", col.regions=col, main="Swiss Language Regions")
AnthroSpace: Download Global Administrative Areas as RData files
Are there any maps of Russia?
Posted by: simulyant | October 21, 2009 at 06:43
Sweet indeed :o) thank you for a really useful post
Posted by: Amy | October 21, 2009 at 10:21
And, Hadley has good mapping support in ggplot2. See http://sites.google.com/site/acommarketinganalytics/
Posted by: Jim Porzak | October 21, 2009 at 11:34
Thanks for the pointer to this data, David. It's going to save me a ton of time in the future! It's just unfortunate that their licenses are rather restrictive (no commercial use).
Posted by: Hadley | October 21, 2009 at 12:01
It's nice to have maps with administrative boundaries for non-US countries. Thanks for this!
Posted by: Jay | November 02, 2009 at 08:25
Hi,
i am trying to handle my country map (italy) but I didn't found any information about "internal" vars like example's language.
Hints? Tools? functions? Let's me know, please.
Posted by: Daniele | November 17, 2009 at 07:45
@Daniele: you have to add those variables (for example, with a vector as above), they're not 'internal' :-)
You can find useful data for Italy (for example about unemployement) on www.istat.it
Posted by: Marcoscan | November 17, 2009 at 23:23
@Daniele: I have written a post about it, maybe you'll find it useful :-) http://bit.ly/3tz6AU
Posted by: Marcoscan | November 18, 2009 at 10:57
Do you know how to get a map of Venezuela by states?
Posted by: Mary | December 11, 2009 at 03:03
Informative geographical map information on how to create a USA map from The R Project for Statistical Computing. Thanks.
Posted by: State Maps Online | April 07, 2010 at 12:42
Thanks sharing ..
Posted by: ScorpioN | October 10, 2010 at 08:01
Dear David,
I am trying to create a map with central asian countries(Kazakhstan, Uzbekstan, Kyrgyzstan, Turkmenstan, and Tajikstan) in the same graphic. Since I am new with R, I can't seem to find a better solution to it. Any ideas?
Posted by: Batur | September 14, 2011 at 19:29
What's the file format if you have your own map data that you'd like the maps routines to read in?
Posted by: Jake | October 28, 2011 at 13:09
is GADM down? not working form me today!
Posted by: Juan Serrano | February 07, 2013 at 18:32
Used this package to make a great visualization for a project idea. Good stuff!
Posted by: Joe R | April 18, 2013 at 11:03