Created
December 4, 2009 01:01
-
-
Save markheckmann/248746 to your computer and use it in GitHub Desktop.
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
### DATA PREP ### | |
# loading the unemployment data | |
unempl <- read.delim2(file="./data/data_germany_unemployment_by_ | |
county.txt", header = TRUE, sep = "\t", | |
dec=",", stringsAsFactors=F) | |
# due to Mac OS encoding, otherwise not needed | |
gadm_names <- iconv(gadm$NAME_3, "ISO_8859-2", "UTF-8") | |
# fuzzy matching of data: quick & dirty | |
# caution: this step takes some time ~ 2 min. | |
# parsing out "Städte" | |
gadm_names_n <- gsub("Städte", "", gadm_names) | |
total <- length(gadm_names) | |
# create progress bar | |
pb <- txtProgressBar(min = 0, max = total, style = 3) | |
order <- vector() | |
for (i in 1:total){ | |
order[i] <- agrep(gadm_names_n[i], unempl$Landkreis, | |
max.distance = 0.2)[1] | |
setTxtProgressBar(pb, i) # update progress bar | |
} | |
# choose color by unemployment rate | |
col_no <- as.factor(as.numeric(cut(unempl$Wert[order], | |
c(0,2.5,5,7.5,10,15,100)))) | |
levels(col_no) <- c(">2,5%", "2,5-5%", "5-7,5%", | |
"7,5-10%", "10-15%", ">15%") | |
gadm$col_no <- col_no | |
myPalette<-brewer.pal(6,"Purples") | |
# plotting | |
spplot(gadm, "col_no", col=grey(.9), col.regions=myPalette, | |
main="Unemployment in Germany by district") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment