## ## 2014 Unemployment Data Micromaps ## library(micromap) library(maps) library(maptools) library(rgdal) iowa <- map("county", "iowa", plot = FALSE, fill = TRUE) sp <- map2SpatialPolygons(iowa, iowa$names) readLAUS <- function(file = "http://www.stat.uiowa.edu/~luke/classes/STAT7400/data/laucntycur14-2014.txt") { fullData <- read.table(file, col.names = c("LAUSAreaCode", "State", "County", "Title", "Period", "LaborForce", "Employed", "Unemployed", "UnempRate"), quote = '"', sep = "|", skip = 6, stringsAsFactors = FALSE, strip.white = TRUE, fill = TRUE) ## remove footer footstart <- grep("------", fullData$LAUSAreaCode) fullData <- fullData[1:(footstart - 1),] ## separate out state, county names fullData$StateCharCode <- sub("^.*, ", "", fullData$Title) fullData$CountyName <- sub(", .*", "", fullData$Title) ## remove commas from numbers and convert to numeric fullData$LaborForce <- as.numeric(gsub(",", "", fullData$LaborForce)) fullData$Employed <- as.numeric(gsub(",", "", fullData$Employed)) fullData$Unemployed <- as.numeric(gsub(",", "", fullData$Unemployed)) fullData } laus <- readLAUS() ilaus <- subset(laus, StateCharCode == "IA") df <- data.frame(Nov13 = subset(ilaus, Period == "Nov-13")$UnempRate, May14 = subset(ilaus, Period == "May-14")$UnempRate, Nov14 = subset(ilaus, Period == "Nov-14")$UnempRate, county = sub(".*,", "", iowa$names), row.names = iowa$names) spdf <- SpatialPolygonsDataFrame(sp, data = df) maptab <- create_map_table(spdf, IDcolumn = "county") lmplot(stat.data=df, map.data = maptab, grouping = 10, ord.by = "Nov13", panel.types=c("labels", "dot", "dot", "map"), panel.data = c("county", "Nov13", "Nov14", NA), map.link=c("county", "ID"), plot.height = 9, panel.att = list(list(1, text.size = 0.6), list(2, header = "Nov 13"), list(3, header = "Nov 14"))) lmplot(stat.data=df, map.data = maptab, grouping = 10, ord.by = "Nov13", panel.types=c("labels", "dot", "dot", "dot", "map"), panel.data = c("county", "Nov13", "May14", "Nov14", NA), map.link=c("county", "ID"), plot.height = 9, panel.att = list(list(1, text.size = 0.6), list(2, header = "Nov 13"), list(3, header = "May 14"), list(4, header = "Nov 14")))