Created
May 14, 2014 10:53
-
-
Save pachevalier/38666a7fecab76f986b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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