Skip to content

Instantly share code, notes, and snippets.

@pecard
Forked from jlowin/ggplot2.r
Created January 7, 2010 17:14
Show Gist options
  • Save pecard/271376 to your computer and use it in GitHub Desktop.
Save pecard/271376 to your computer and use it in GitHub Desktop.
#! Mapa distribuição de variáveis sobre maps do pack map - GGPLOT
library(ggplot2)
#extract reference data
mapcounties <- map_data("county")
mapstates <- map_data("state")
#merge data with ggplot county coordinates
mapcounties$county <- with(mapcounties , paste(region, subregion, sep = ","))
mergedata <- merge(mapcounties, unemp_data, by.x = "county", by.y = "counties")
mergedata <- mergedata[order(mergedata$order),]
#draw map
map <- ggplot(mergedata, aes(long,lat,group=group)) + geom_polygon(aes(fill=colorBuckets))
map <- map + scale_fill_brewer(palette="PuRd") + coord_map(project="globular") + opts(legend.position = "none")
#add state borders
map <- map + geom_path(data = mapstates, colour = "white", size = .75)
#add county borders
map <- map + geom_path(data = mapcounties, colour = "white", size = .5, alpha = .1)
map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment