Last active
August 29, 2015 14:02
-
-
Save dataspam/7c2692f609fd1b47a155 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
# colClasses forces the FIPSFULL row to keep their leading zeros | |
PerPovData <- read.csv("data/persistent_poverty-full.csv", colClasses=c("FIPSFULL"="character")) | |
library(rgeos) | |
library(maptools) | |
#Prep Continental Map | |
fips_dist <- readShapeSpatial("maps/fips/basic/US_County_AK_2000_2004.shp") | |
# if you want to check to see if it plots correctly: plot(fips_dist), but I know this is working for me | |
fips_dist <- fortify(fips_dist, region = "FIPS") | |
fips_dist$id <- toupper(fips_dist$id) | |
#Prep Alaska and Hawaii Map | |
fips_dist2 <- readShapeSpatial("maps/fips/full/tl_2013_us_county.shp") | |
fips_dist2 <- fortify(fips_dist2, region = "GEOID") | |
fips_dist2$id <- toupper(fips_dist2$id) | |
library(ggplot2) | |
#Plot Continental Map | |
p <- ggplot() | |
p <- p + geom_map(data = PerPovData, aes(map_id = FIPSFULL, fill = POV), colour = "grey10", lwd=.15, map = fips_dist) | |
p <- p + expand_limits(x = fips_dist$long, y = fips_dist$lat) | |
p <- p + theme(panel.background = element_rect(fill = "white"), line = element_blank()) | |
p <- p + scale_fill_gradient2(low = "dodgerblue3", mid = "dodgerblue3", midpoint = .1, high = "firebrick2" , limits = c(0, 1)) | |
p <- p + theme(legend.title=element_text(size=14)) | |
print(p) | |
# Plot Alaska separately; guides(fill=FALSE) removes the legend, which you're going to use from the Continental map anywayz | |
# x & y lims came from trial and error | |
# higher lwd due to different shapefile not looking quite as pretty | |
p2 <- ggplot() | |
p2 <- p2 + geom_map(data = PerPovData, aes(map_id = FIPSFULL, fill = POV), colour = "grey10", lwd=.3, map = fips_dist2) | |
p2 <- p2 + expand_limits(x = fips_dist2$long, y = fips_dist2$lat) | |
p2 <- p2 + xlim(-175,-130) | |
p2 <- p2 + ylim(50,75) | |
p2 <- p2 + theme(panel.background = element_rect(fill = "white"), line = element_blank()) | |
p2 <- p2 + scale_fill_gradient2(low = "dodgerblue3", mid = "dodgerblue3", midpoint = .1, high = "firebrick2" , limits = c(0, 1)) | |
p2 <- p2 + theme(legend.title=element_text(size=14)) | |
p2 <- p2 + guides(fill=FALSE) | |
print(p2) | |
# Plot Hawaii separately | |
p3 <- ggplot() | |
p3 <- p3 + geom_map(data = PerPovData, aes(map_id = FIPSFULL, fill = POV), colour = "grey10", lwd=.2, map = fips_dist2) | |
p3 <- p3 + expand_limits(x = fips_dist2$long, y = fips_dist2$lat) | |
p3 <- p3 + xlim(-175,-130) | |
p3 <- p3 + ylim(15,30) | |
p3 <- p3 + theme(panel.background = element_rect(fill = "white"), line = element_blank()) | |
p3 <- p3 + scale_fill_gradient2(low = "dodgerblue3", mid = "dodgerblue3", midpoint = .1, high = "firebrick2" , limits = c(0, 1)) | |
p3 <- p3 + theme(legend.title=element_text(size=14)) | |
p3 <- p3 + guides(fill=FALSE) | |
print(p3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment