Created
November 13, 2009 03:02
-
-
Save jlowin/233554 to your computer and use it in GitHub Desktop.
choropleth data prep
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 <- read.csv("state abbr.csv") | |
rownames(stateAbbr) <- stateAbbr$ABB | |
unemp_data <- read.csv("unemp_county.csv") | |
#get county names in correct format | |
countyNames <- sapply(as.character(unemp_data$CountyName),strsplit,", ") | |
counties <- sapply(countyNames ,"[",1) | |
states <- sapply(countyNames ,"[",2) | |
states <- as.character(stateAbbr[states,2]) | |
#concatenate states and counties | |
unemp_data$counties <- tolower(paste(states,counties,sep=",")) | |
#parse out county titles & specifics | |
unemp_data$counties <- sub(" county","",unemp_data$counties) | |
unemp_data$counties <- sub(" parish","",unemp_data$counties) | |
unemp_data$counties <- sub(" borough","",unemp_data$counties) | |
unemp_data$counties <- sub("miami-dade","dade",unemp_data$counties) | |
#define color buckets | |
colors = c("#F1EEF6", "#D4B9DA", "#C994C7", "#DF65B0", "#DD1C77", "#980043") | |
unemp_data$colorBuckets <- as.factor(as.numeric(cut(unemp_data$unemp,c(0,2,4,6,8,10,100)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment