Created
October 12, 2011 11:48
-
-
Save reubano/1281016 to your computer and use it in GitHub Desktop.
Choropleths in R
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
#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 |
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(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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 ||