Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Choropleths in R
#load data
stateAbbr rownames(stateAbbr)unemp_data
#get county names in correct format
countyNames counties statesstates
#concatenate states and counties
unemp_data$counties
#parse out county titles & specifics
unemp_data$counties unemp_data$counties unemp_data$countiesunemp_data$counties
#define color buckets
colors = c("#F1EEF6", "#D4B9DA", "#C994C7", "#DF65B0", "#DD1C77", "#980043")
unemp_data$colorBuckets
library(maps)
#align data with map definitions
mapnamescolorsmatched
#draw map
map("county",col = colors[unemp_data$colorBuckets[match(mapnames ,unemp_data$counties)]],
fill = TRUE,resolution = 0,lty = 0,projection = "polyconic")
map("state",col = "white",fill=FALSE,add=TRUE,lty=1,lwd=1,projection="polyconic")
@reubano

This comment has been minimized.

Copy link
Owner Author

commented Oct 12, 2011

site: http://www.thisisthegreenroom.com/2009/choropleths-in-r/
data: http://datasets.flowingdata.com/unemployment09.csv

“state abbr.csv” is a simple file I created to provide a mapping between state names and state abbreviations — as I recall, the data format and the necessary format in R were not the same. The file looked like this: New Jersey | NJ || New Mexico | NM || New York | NY ||

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.