Created
June 27, 2013 00:56
-
-
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
This file contains hidden or 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
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