Skip to content

Instantly share code, notes, and snippets.

@pachevalier
Created May 14, 2014 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pachevalier/38666a7fecab76f986b4 to your computer and use it in GitHub Desktop.
Save pachevalier/38666a7fecab76f986b4 to your computer and use it in GitHub Desktop.
library(rgdal)
library(ggplot2)
library(maptools)
library(ggthemes)
# data from http://thematicmapping.org/downloads/TM_WORLD_BORDERS_SIMPL-0.3.zip
gpclibPermit()
world.map <- readOGR(dsn="data/TM_WORLD_BORDERS_SIMPL-0.3/", layer="TM_WORLD_BORDERS_SIMPL-0.3")
world.ggmap <- fortify(world.map, region = "ISO3")
str(world.ggmap)
# sample data
test <- data.frame(id = unique(world.ggmap$id))
test$x <- rnorm(n=nrow(test))
map <- ggplot(data = test, aes(fill = x)) +
geom_map(aes(map_id = id), map =world.ggmap, color = "white") +
expand_limits(x = world.ggmap$long, y = world.ggmap$lat) +
theme_tufte()
# draw map
png("output/ggmap.png")
map + coord_map()
dev.off()
png("output/ggmap2.png")
map
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment