Created
October 20, 2016 00:41
-
-
Save morganmelon/e62afa541c69395bd62f23ade2bee76e to your computer and use it in GitHub Desktop.
Black/White Segregation Indices by State 2005-9
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
#Morgan Waterman | |
#Lab 5 | |
#Mapping Segregation By State 1940-2010 | |
#load packages | |
library(readr) | |
library(dplyr) | |
library(ggplot2) | |
library(RColorBrewer) | |
library(ggmap) | |
library(maptools) | |
library(gtools) | |
library(devtools) | |
library(gganimate) | |
#read in map dataframe | |
mapdata <-read_csv('data/map.csv') | |
#Create map base | |
map1 <-ggplot() + scale_fill_brewer(palette='Greens') + theme_nothing(legend=TRUE) + | |
geom_polygon(data=mapdata, aes(x=long, y=lat, group=group), fill='white', color='black') | |
png('mapped.png', width=1500, height=1000) | |
print(map1) | |
dev.off() | |
#read in data extract | |
ipums <- read_csv('data/SegregationIndicesByState.csv') | |
ipums <- ipums %>% arrange(State) | |
cuts <- quantcut(ipums$Index, q=seq(0,1,.2)) | |
#create categories by segregation indices | |
segcats <- ipums %>% mutate(Indices = factor(ifelse(Index<=55, 1, | |
ifelse(Index<=59, 2, | |
ifelse(Index<=62, 3, | |
ifelse(Index<=68, 4,5)))))) | |
levels(segcats$Indices) <- c('0-55', '56-59', '60-62', '63-68', '69+') | |
segmap <- left_join(segcats, mapdata, by = c('State' = 'id')) %>% arrange(order) | |
map2 <- map1 + | |
geom_polygon(data=segmap, aes(x=long, y=lat, group=group, fill=Indices), color= 'black') + | |
labs(title = 'Segregation Indices by State 2005-9') | |
png('mapseg.png', width= 1500, height=1000) | |
print(map2) | |
dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment