Dallas Geographies and Race/Eth Data Exports

Author

Sarah Serpas

Exporting Maps + Creating Neighborhood Designations

From p. 13 of 2019 Report: “Although most of the indicators that compare outcomes by race/ethnicity use individual-level data, this data was unavailable in some instances. For those indicators, neighborhoods (defined by census tracts or zip codes) are used as a proxy. In this report, we compare neighborhoods according to their majority (more than 50%) racial/ethnic makeup. If no majority exists, we label that neighborhood”racially diverse.” In Dallas, the following majority racial/ethnic groups for neighborhoods are used: White, Black, and Hispanic. No neighborhoods were majority-Asian in either year.”

Note: for tract and zip code data, we have to use 5 year ACS. This will be used for both the 2019 and 2021 samples.

Data Pulls + Calcs: PUMAs

#install.packages("tidycensus")
library(tidycensus)
acs2021 <- load_variables(2021 , "acs5", cache = TRUE) 
library(dplyr)

tx_puma<-get_acs(geography = "puma",
                   state="TX",
                   year = 2021,
                   survey = "acs5",
                variables=c("B03002_001E",
                            "B03002_003E",
                            "B03002_004E",
                            "B03002_006E",
                            "B03002_007E", 
                            "B03002_005E", 
                            "B03002_008E",
                            "B03002_009E",
                            "B03002_012E"),
                geometry = T, output = "wide")


#select tracts that have nonzero population
#dal_tract <- filter(dal_tract, B03002_001E>0)

#rename variables
tx_puma<-tx_puma%>%
  mutate(totpop=B03002_001E,
         whiteNH = B03002_003E,
         blackNH = B03002_004E,
         aapiNH = B03002_006E + B03002_007E, 
         aianNH = B03002_005E, 
         oth2NH = B03002_008E + B03002_009E,
         HispLat = B03002_012E,
         pwhiteNH = whiteNH/totpop,
         pblackNH = blackNH/totpop,
         paapiNH = aapiNH/ totpop,
         paianNH = aianNH/totpop,
         poth2NH = oth2NH/ totpop,
         pHispLat = HispLat / totpop,
         pctPOC = 1 - pwhiteNH)


tx_places<-get_acs(geography = "place", state="Texas", variables=c("DP05_0001E"), year=2021, geometry = T, output = "wide")
dallas_place<-tx_places[tx_places$GEOID=="4819000",]
dal_codes<-c(4802304,4802305,4802306,4802307,4802309,4802310,4802311,4802312,4802313,4802314,4802315,4802316,4802319,4801901,4802001)
dal_codes_string<-c("4802304","4802305","4802306","4802307","4802309","4802310","4802311","4802312","4802313","4802314","4802315","4802316","4802319","4801901","4802001")
dallas_puma <-tx_puma[tx_puma$GEOID %in% dal_codes,]
  
#install.packages("tmap")
library(tmap)
tmap_mode("view")
library(sf)
dallas_bb<- st_bbox(dallas_place)
puma_bb <-st_bbox(dallas_puma)

dallas_puma$nb_race <- ifelse(dallas_puma$pwhiteNH>0.5,"Majority White NH",(ifelse(dallas_puma$pblackNH>0.5,"Majority Black NH",(ifelse(dallas_puma$paapiNH>0.5,"Majority AAPI NH",(ifelse(dallas_puma$poth2NH>0.5,"Majority Other or 2+ NH",(ifelse(dallas_puma$pHispLat>0.5,"Majority Hispanic/Latino","Racially Diverse")))))))))


dallas_puma_exp <- dallas_puma[,c("GEOID",  "NAME", "totpop",   "whiteNH",  "blackNH",  "aapiNH",   "aianNH",   "oth2NH",   "HispLat",  "pwhiteNH", "pblackNH", "paapiNH",  "paianNH",  "poth2NH",  "pHispLat", "pctPOC", "nb_race")] #selecting only the columns I want

st_write(dallas_puma_exp, "dal_puma_race_eth.shp", append=FALSE)

Data Pulls + Calcs: Census Tracts

Note that there are many more geographies shown here than we use in the report - this was casting a wide net and just gathering all tracts for the five counties that intersect the City of Dallas.

#NOTE: 5 Year ACS for tracts in Dallas' intersecting Counties (Dallas, Collin, Denton, Kaufman, Rockwall)
dal_counties <- df <- data.frame (CountyName  = c("Dallas", "Collin", "Denton", "Kaufman", "Rockwall"),
                  CountyFIPS3 = c("113","085","121","257","397"), 
                  CountyFIPS5 = c("48113","48085","48121","48257","48397"))

dal_tract<-get_acs(geography = "tract",
                   state="TX",
                   county = dal_counties$CountyFIPS3,
                   year = 2021,
                   survey = "acs5",
                variables=c("B03002_001E",
                            "B03002_003E",
                            "B03002_004E",
                            "B03002_006E",
                            "B03002_007E", 
                            "B03002_005E", 
                            "B03002_008E",
                            "B03002_009E",
                            "B03002_012E"),
                geometry = T, output = "wide")


#select tracts that have nonzero population
#dal_tract <- filter(dal_tract, B03002_001E>0)

#rename variables
dal_tract<-dal_tract%>%
  mutate(totpop=B03002_001E,
         whiteNH = B03002_003E,
         blackNH = B03002_004E,
         aapiNH = B03002_006E + B03002_007E, 
         aianNH = B03002_005E, 
         oth2NH = B03002_008E + B03002_009E,
         HispLat = B03002_012E,
         pwhiteNH = whiteNH/totpop,
         pblackNH = blackNH/totpop,
         paapiNH = aapiNH/ totpop,
         paianNH = aianNH/totpop,
         poth2NH = oth2NH/ totpop,
         pHispLat = HispLat / totpop,
         pctPOC = 1 - pwhiteNH)

dal_tract$nonzero_pop <- ifelse(dal_tract$totpop>0,1,0)

dal_tract$nb_race <- ifelse(dal_tract$pwhiteNH>0.5,"Majority White NH",(ifelse(dal_tract$pblackNH>0.5,"Majority Black NH",(ifelse(dal_tract$paapiNH>0.5,"Majority AAPI NH",(ifelse(dal_tract$poth2NH>0.5,"Majority Other or 2+ NH",(ifelse(dal_tract$pHispLat>0.5,"Majority Hispanic/Latino",(ifelse(dal_tract$nonzero_pop==1,"Racially Diverse",0)))))))))))

table(dal_tract$neighb_race)


dal_tract_exp <- dal_tract[,c("GEOID",  "NAME", "totpop",   "whiteNH",  "blackNH",  "aapiNH",   "aianNH",   "oth2NH",   "HispLat",  "pwhiteNH", "pblackNH", "paapiNH",  "paianNH",  "poth2NH",  "pHispLat", "pctPOC", "nb_race")] #selecting only the columns I want

st_write(dal_tract_exp, "dal_tract_race_eth.shp", append=FALSE)

#install.packages("writexl")
#library("writexl")
#write_xlsx(dal_tract,"~/Desktop/Temp/table.xlsx")


#grab dallas city boundary
tx_places<-get_acs(geography = "place", state="Texas", variables=c("DP05_0001E"), year=2021, geometry = T, output = "wide")
dallas_place<-tx_places[tx_places$GEOID=="4819000",]
st_write(dallas_place, "city_dallas_place.shp", append=FALSE)

Data Pulls + Calcs: Zip Codes

dal_counties_geo<-get_acs(geography = "county",
                   year = 2021,
                   state = "TX",
                   county = dal_counties$CountyFIPS3,
                   survey = "acs5",
                variables=c("B03002_001E"),
                geometry = T, output = "wide")

us_zip<-get_acs(geography = "zip code tabulation area",
                   year = 2021,
                   survey = "acs5",
                variables=c("B03002_001E",
                            "B03002_003E",
                            "B03002_004E",
                            "B03002_006E",
                            "B03002_007E", 
                            "B03002_005E", 
                            "B03002_008E",
                            "B03002_009E",
                            "B03002_012E"),
                geometry = T, output = "wide")

#filter for dallas Zip codes (intersect the counties)
dal_zip <- us_zip[dal_counties_geo, , op = st_intersects]

#rename variables
dal_zip<-dal_zip%>%
  mutate(totpop=B03002_001E,
         whiteNH = B03002_003E,
         blackNH = B03002_004E,
         aapiNH = B03002_006E + B03002_007E, 
         aianNH = B03002_005E, 
         oth2NH = B03002_008E + B03002_009E,
         HispLat = B03002_012E,
         pwhiteNH = whiteNH/totpop,
         pblackNH = blackNH/totpop,
         paapiNH = aapiNH/ totpop,
         paianNH = aianNH/totpop,
         poth2NH = oth2NH/ totpop,
         pHispLat = HispLat / totpop,
         pctPOC = 1 - pwhiteNH)

dal_zip$nonzero_pop <- ifelse(dal_zip$totpop>0,1,0)

dal_zip$nb_race <- ifelse(dal_zip$pwhiteNH>0.5,"Majority White NH",(ifelse(dal_zip$pblackNH>0.5,"Majority Black NH",(ifelse(dal_zip$paapiNH>0.5,"Majority AAPI NH",(ifelse(dal_zip$poth2NH>0.5,"Majority Other or 2+ NH",(ifelse(dal_zip$pHispLat>0.5,"Majority Hispanic/Latino",(ifelse(dal_zip$nonzero_pop==1,"Racially Diverse",0)))))))))))

table(dal_zip$neighb_race)


dal_zip_exp <- dal_zip[,c("GEOID",  "NAME", "totpop",   "whiteNH",  "blackNH",  "aapiNH",   "aianNH",   "oth2NH",   "HispLat",  "pwhiteNH", "pblackNH", "paapiNH",  "paianNH",  "poth2NH",  "pHispLat", "pctPOC",   "nb_race")] #selecting only the columns I want

#export to shapefile
st_write(dal_zip_exp, "dal_zip_race_eth.shp", append=FALSE)

Maps for Three Geographies

PUMA Map 1: Percent POC Population by Tract (2021 5 YR ACS)

library(tmap)    
tm_shape(dallas_puma,bbox = dallas_bb)+   
  tm_polygons("pctPOC",
              title="PUMAs",
              border.alpha = 0.25, 
              palette="YlGnBu", 
              border.col = "black",
              style="pretty",
              legend.hist=TRUE)+   
  tm_format("World", 
            title="PUMA Share Population of Color, 2017-2021 5 YR ACS", 
            legend.outside=T)+    
  tm_shape(dallas_place)+       
  tm_polygons(alpha=0,border.col="black")+   
  tm_scale_bar(position="LEFT") 

PUMA Map 2: Neighborhood Racial Categorization

tm_shape(dallas_puma,bbox = dallas_bb)+   
  tm_polygons("nb_race",
              title="PUMAs",
              border.alpha = 0.25, 
              palette="Set2", 
              border.col = "black",
              style="pretty",
              legend.hist=TRUE)+   
  tm_format("World", 
            title="PUMA Categorization, 2017-2021 5 YR ACS", 
            legend.outside=T)+     
  tm_shape(dallas_place)+       
  tm_polygons(alpha=0,border.col="black")+   
  tm_scale_bar(position="LEFT")    
#Below to explore color palettes via Color Brewer 
#  library (tmaptools) 
#  install.packages("shinyjs") 
#  palette_explorer() 
#  get_brewer_pal("Set2", n = 5)

Tract Map 1: Percent POC Population by Tract (2021 5 YR ACS)

tm_shape(dal_tract,bbox = dallas_bb)+   
  tm_polygons("pctPOC",
              title="Tracts",
              border.alpha = 0.25, 
              palette="YlGnBu", 
              border.col = "black",
              style="pretty",
              legend.hist=TRUE)+   
  tm_format("World", 
            title="Tract Categorization, 2017-2021 5 YR ACS", 
            legend.outside=T)+     
  tm_shape(dallas_place)+       
  tm_polygons(alpha=0,border.col="black")+   
  tm_scale_bar(position="LEFT")   

Tract Map 2: Neighborhood Racial Categorization

tm_shape(dal_tract,bbox = dallas_bb)+   
  tm_polygons("nb_race",
              title="Tracts",
              border.alpha = 0.25, 
              palette="Set2",
              border.col = "black",
              style="pretty",
              legend.hist=TRUE)+   
  tm_format("World", 
            title="Tract Categorization, 2017-2021 5 YR ACS", 
            legend.outside=T)+     
  tm_shape(dallas_place)+       
  tm_polygons(alpha=0,border.col="black")+   
  tm_scale_bar(position="LEFT")    

ZCTA Map 1: Percent POC Population by Zip Code (2021 5 YR ACS)

tm_shape(dal_zip,bbox = dallas_bb)+   
  tm_polygons("pctPOC",
              title="Zip Code",
              border.alpha = 0.25, 
              palette="YlGnBu", 
              border.col = "black",
              style="pretty",
              legend.hist=TRUE)+   
  tm_format("World", 
            title="Zip Code Share Population of Color, 2017-2021 5 YR ACS", 
            legend.outside=T)+     
  tm_shape(dallas_place)+       
  tm_polygons(alpha=0,border.col="black")+   
  tm_scale_bar(position="LEFT")  

ZCTA Map 2: Neighborhood Racial Categorization

tm_shape(dal_zip,bbox = dallas_bb)+   tm_polygons("nb_race",title="Zip Codes",border.alpha = 0.25, palette="Set2", border.col = "black",style="pretty",legend.hist=TRUE)+   tm_format("World", title="Zip Code Categorization, 2017-2021 5 YR ACS", legend.outside=T)+     tm_shape(dallas_place)+       tm_polygons(alpha=0,border.col="black")+   tm_scale_bar(position="LEFT")+   tm_compass()
Compass not supported in view mode.