This example shows how to calculate an index of education segregation for Bexar County, TX using data from the 2018 American Community Survey

Some measures of economic segregation are calculated by the Census bureau directly, in the American Community Survey, the Census provides the Gini Index of income inequality for many geographies. This measure is widely used in economics and give a general picture of the equality of the income distribution within a place, although it says nothing about how the different income groups live with respect to one another.

A second measure of income segregation is very simple to calculate, although it is frequently criticized as being arbitrary. It is the ratio of the median household income in each subarea to the median household income in the larger area. It is also easy to interpret. If a subarea has a lower income than the larger area, the index will be less than one, and if a subarea has a higher income, the index is greater than one.

You can find maps of this index for many US metro areas through the Brown University Diversity and Disparities project, which provides maps of this ratio.

Below, I show how this can be easily calculated in R, and this can easily be modified for a different county of interest.

library(ggplot2)
library(tidycensus)
library(tigris)
library(dplyr)
library(mapview)

The next example will be to calculate the educatoin ratio index which we described above, while not ideal, this should provide a simple visualization of inequality within places.

First, we query the percent of the population over age 25 with a college education in Bexar Census tracts, then the same variable for Bexar county as a whole, and form the ratio.

bex_tract<-get_acs(geography="tract", state = "TX", county = "Bexar", year=2018,variables = "DP02_0064PE", output = "wide", geometry = T)
## Getting data from the 2014-2018 5-year ACS
## Downloading feature geometry from the Census website.  To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Using the ACS Data Profile
bex_tract<-bex_tract%>%
  mutate(pct_college_tr = DP02_0064PE, cofips=substr(GEOID, 1,5))

pa_counties<-get_acs(geography="county", state = "TX",output="wide",  year=2018,variables = "DP02_0064PE")
## Getting data from the 2014-2018 5-year ACS
## Using the ACS Data Profile
bex_county<-pa_counties%>%
  filter(GEOID=="48029")%>%
  mutate(pct_college = DP02_0064PE)%>%
  select(GEOID, pct_college)

bexar_merge<-geo_join(bex_tract, bex_county, by_sp="cofips", by_df="GEOID")

bexar_merge$edu_ratio<-bexar_merge$pct_college_tr/bexar_merge$pct_college

Now we create a map of the ratio in the tracts within Bexar County. We see a huge gap among the North and South sides of the county, with pockets of low education interspersed among northside communities.

bexar_merge%>%
  filter(is.na(edu_ratio)==F)%>%
  mutate(edu_ratio = cut(edu_ratio, breaks = c(0, .5, 1, 1.5, 2, 2.5, 5, 10) , include.lowest = T))%>%
  ggplot()+geom_sf(aes(fill=edu_ratio))+
  scale_fill_brewer(palette = "RdBu")+
  scale_color_brewer(palette = "RdBu")+
  ggtitle("Ratio of Tract % with College Education to County Level", subtitle = "Bexar County, TX - 2018 ACS")

mapviewOptions(vector.palette = colorRampPalette(RColorBrewer::brewer.pal(n = 7, name = "RdBu")),
               na.color = "grey",
               layers.control.pos = "topright")

mapview(bexar_merge["edu_ratio"], layer.name="Education Ratio")