Skip to content

Instantly share code, notes, and snippets.

@Ram-N
Created June 27, 2013 00:56
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 Ram-N/5873164 to your computer and use it in GitHub Desktop.
Save Ram-N/5873164 to your computer and use it in GitHub Desktop.
choropleth.R How to create a simple choropleth for all US States. In this simple example, we plot the alphabetically sorted value of the state to a color scale
states_map <- map_data("state")
region <- tolower(state.name)
count.vector <- 1:50 # just a value
df<- data.frame(region, count.vector)
pal <- colorRampPalette(c('grey10','darkgreen'))(50)
mp <- ggplot(df, aes(map_id=region)) + geom_map(aes(fill=count.vector), map=states_map) + coord_map("polyconic") + expand_limits(x = states_map$long, y = states_map$lat)
mp <- mp + scale_fill_gradient(low='grey90', high='darkgreen', limits=c(0,100))
mp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment