Most Prosperous Neighborhoods in Philadelphia

Julian Hartwell Prompt 3 2/10/21

Introduction

For this assignment I wanted to look at the most prosperous neighborhoods in Philadephia to live in. By using pooled five-year data from the American Community Survey, I was able to approximate median household income and median rent for each tract in Philadelphia. I created an Affordable variable that took the difference between these two statistics to arrive at Philadelphia’s most prosperous neighborhoods.

The next three code chunks read in my libaries and custom functions, pull in 2005-2009 ACS data, and manipulate the dataframe.

#load libraries
library(tidycensus)
library(tidyverse)
library(sf)

#load custom functions
mapTheme <- function(base_size = 12) {
  theme(
    text = element_text( color = "black"),
    plot.title = element_text(size = 16,colour = "black"),
    plot.subtitle=element_text(face="italic"),
    plot.caption=element_text(hjust=0),
    axis.ticks = element_blank(),
    panel.background = element_blank(),axis.title = element_blank(),
    axis.text = element_blank(),
    axis.title.x = element_blank(),
    axis.title.y = element_blank(),
    panel.grid.minor = element_blank(),
    panel.border = element_rect(colour = "black", fill=NA, size=2),
    strip.text.x = element_text(size = 14))
}

qBr <- function(df, variable, rnd) {
  if (missing(rnd)) {
    as.character(quantile(round(df[[variable]],0),
                          c(.01,.2,.4,.6,.8), na.rm=T))
  } else if (rnd == FALSE | rnd == F) {
    as.character(formatC(quantile(df[[variable]]), digits = 3),
                 c(.01,.2,.4,.6,.8), na.rm=T)
  }
}

q5 <- function(variable) {as.factor(ntile(variable, 5))}

# Load hexadecimal color palette

palette5 <- c("#f0f9e8","#bae4bc","#7bccc4","#43a2ca","#0868ac")
#getting started
#tidycensus requires a census key to run
#pulling MedHHInc and MedRent by Philly tract from 2005-2009 ACS

#census_api_key("YOUR_KEY_HERE", overwrite = TRUE)
tracts09 <-  
  get_acs(geography = "tract", variables = c("B19013_001E","B25058_001E"), 
          year=2009, state=42, county=101, geometry=T) %>% 
  st_transform('ESRI:102728')
#spread data into wide from
#create Affordable variable
spread09 <- 
  tracts09 %>%
  dplyr::select( -NAME, -moe) %>%
  spread(variable, estimate) %>%
  dplyr::select(-geometry) %>%
  rename(MedHHInc = B19013_001, 
         MedRent = B25058_001) %>%
  mutate(Affordable = MedHHInc - MedRent*12)


ggplot() +
  geom_sf(data = spread09, aes(fill = q5(Affordable))) +
  scale_fill_manual(values = palette5,
                    labels = paste("$",qBr(spread09, "Affordable")),
                    name = "Median Income less Rent\n(Quintile Breaks)") +
  labs(title = "Most Prosperous Neighborhoods", subtitle = "Philadelphia; 2005-2009",
       caption = "Source: 5-year pooled American Community Survey") +
  mapTheme() + theme(plot.title = element_text(size=22))

Changes over Time

Philadelphia’s least prosperous tracts only had a $6k difference between household income and rent. The most prosperous tracts had $42k in post-rent income. These tracts were a portion of center city as well as the outer-lying subrurbs in the northwest and northeast.

Next I ran this same analysis for the 2014-2018 ACS data. The findings point to growing income inequality in the city. The least prosperous districts barely changed during this period, while the more prosperous districts witnessed even more post-rent income. For example, the most prosperous tracts jumped from $42k to $52k in disposable income. Additionally, more tracts in center city saw an influx of prosperity. While this analysis is limited, it would be interesting to understand whether this was more a result of income changes or rent changes.

#Has the data changed over time?
#pulling MedHHInc and MedRent by Philly tract from 2014-2018
tracts18 <-  
  get_acs(geography = "tract", variables = c("B19013_001E","B25058_001E"), 
          year=2018, state=42, county=101, geometry=T) %>% 
  st_transform('ESRI:102728')
#spread data into wide from
spread18 <- 
  tracts18 %>%
  dplyr::select( -NAME, -moe) %>%
  spread(variable, estimate) %>%
  dplyr::select(-geometry) %>%
  rename(MedHHInc = B19013_001, 
         MedRent = B25058_001) %>%
  mutate(Affordable = MedHHInc - MedRent*12)

ggplot() +
  geom_sf(data = spread18, aes(fill = q5(Affordable))) +
  scale_fill_manual(values = palette5,
                    labels = paste("$",qBr(spread18, "Affordable")),
                    name = "Median Income less Rent\n(Quintile Breaks)") +
  labs(title = "Most Prosperous Neighborhoods", subtitle = "Philadelphia; 2014-2018",
       caption = "Source: 5-year pooled American Community Survey") +
  mapTheme() + theme(plot.title = element_text(size=22))