knitr::opts_chunk$set(echo = FALSE)
library(knitr)
library(png)

Project Background

Project Data: tigris Package

include_graphics("fig/3DistrictTypes.png")
include_graphics("fig/Census_tracts.png")

Project Data: tidycensus Package

include_graphics("fig/Tidy_census_data.png")
include_graphics("fig/Census_tract_pop.png")

Methods: Intersection & Area

Example Code

sld_pop_table <- as.data.frame(t(sapply(1:length(state_lower@data$SLDLST), function(z) {
  sd_c_int <- intersect(x =  state_lower[state_lower@data$SLDLST == z,],
                         y = state_tracts_pop)
  dc_area <- gArea(spgeom = sd_c_int, byid = TRUE)/1000000
  percentage <- dc_area/sd_c_int@data$AREA
  Pop_Total <- round(sum(sd_c_int@data$Pop_Total*percentage))
  Pop_White <- round(sum(sd_c_int@data$Pop_White*percentage))
  Pop_Black <- round(sum(sd_c_int@data$Pop_Black*percentage))
  Pop_American_Indian <- round(sum(sd_c_int@data$Pop_American_Indian*percentage))
  Pop_Asian <- round(sum(sd_c_int@data$Pop_Asian*percentage))
  Pop_Hawaian_Pacific_Islander <- round(sum(sd_c_int@data$Pop_Hawaian_Pacific_Islander*percentage))
  Pop_Hispanic <- round(sum(sd_c_int@data$Pop_Hispanic*percentage))
  unlist(data.frame(state_lower[state_lower@data$SLDLST == z,], Pop_Total, Pop_White, Pop_Black,
             Pop_American_Indian, Pop_Asian, Pop_Hawaian_Pacific_Islander,
             Pop_Hispanic))

})))
# converting factors in  data.frame to numeric
sld_pop_table[] <- lapply(sld_pop_table, function(x)
  as.numeric(levels(x))[x])

# merging with  state lower districts
sld_pop <- merge(x = state_lower, y = sld_pop_table, by = "SLDLST")

Results: SpatialPolygon Data Frames

include_graphics("fig/Example_Output_Table.png")

Results: Wisconsin Maps

include_graphics("fig/WISLD_choro.png")
include_graphics("fig/WISUD_choro.png")
include_graphics("fig/WISFCD_choro.png")
include_graphics("fig/WISLD_choro_black.png")
include_graphics("fig/WISUD_choro_black.png")
include_graphics("fig/WISFCD_choro_black.png")

Results: North Carolina Maps

include_graphics("fig/NCSLD_choro.png")
include_graphics("fig/NCSUD_choro.png")
include_graphics("fig/NCSFCD_choro.png")
include_graphics("fig/NCSLD_choro_black.png")
include_graphics("fig/NCSUD_choro_black.png")
include_graphics("fig/NCSFCD_choro_black.png")

Areas for Improvement

Conclusion



simcor06/gerrymanderdem documentation built on May 29, 2019, 9:36 a.m.