Introduction

The data this week comes from Kate Pennington, data.sfgov.org, Vital Signs

Pennington, Kate (2018). Bay Area Craigslist Rental Housing Posts, 2000-2018. Retrieved from https://github.com/katepennington/historic_bay_area_craigslist_housing_posts/blob/master/clean_2000_2018.csv.zip.

Her methodology can be found at her website.

What impact does new housing have on rents, displacement, and gentrification in the surrounding neighborhood? Read our interview with economist Kate Pennington about her article, “Does Building New Housing Cause Displacement?:The Supply and Demand Effects of Construction in San Francisco.”

Kate Pennington on Gentrification and Displacement in San Francisco

You can find datasets on TidyTuesday github repo

Importing Libraries And setting the Theme

library(tidyverse)
library(paletteer)
library(showtext)
library(patchwork)
library(tidytext)
library(reshape2)
library(ggrepel)
library(ggtext)
library(lubridate)
library(janitor)
library(ggthemes)
library(scales)
library(tidyr)
library(lattice)
library(ggridges)

library(repr)
options(repr.plot.width = 20, repr.plot.height =13)

annotate <- ggplot2::annotate

font_add_google('Fira Sans', 'firasans')
showtext_auto()

my_theme <- function() {
  
  # Colors
  color.background = "#030303"
  color.text = "#FFF5EE"
  
  # Begin construction of chart
  theme_bw(base_size=15) +
    
    # Format background colors
    theme(panel.background = element_rect(fill=color.background, color=color.background)) +
    theme(plot.background  = element_rect(fill=color.background, color=color.background)) +
    theme(panel.border     = element_rect(color=color.background)) +
    theme(strip.background = element_rect(fill=color.background, color=color.background)) +
    
    # Format the grid
    theme(panel.grid.major.y = element_blank()) +
    theme(panel.grid.minor.y = element_blank()) +
    theme(panel.grid.major.x = element_blank())+
    theme(panel.grid.minor.x = element_blank()) +
    theme(axis.ticks       = element_blank()) +
    
    # Format title and axis labels
    theme(plot.title       = element_text(color=color.text, size=40, face = "bold", hjust = 0.5, family = 'firasans'))+
    theme(plot.subtitle    = element_text(color=color.text, size=30, face = "bold", hjust = 0.5, family = 'firasans'))+
    theme(plot.caption     = element_text(color=color.text, size=20, face = "bold", hjust = 0.5, family = 'firasans'))+
    theme(axis.title.x     = element_text(size=20, color = color.text, hjust = 0.5, vjust = 0.5,face = "bold", family = 'firasans')) +
    theme(axis.title.y     = element_text(size=20, color = color.text, hjust = 0.5, vjust = 0.5,face = "bold", family = 'firasans')) +
    theme(axis.text.x      = element_text(size=25, color = color.text, hjust = 0.5, vjust = 0.5,face = "bold", family = 'firasans')) +
    theme(axis.text.y      = element_text(size=25, color = color.text, face = "bold", family = 'firasans')) +
    theme(strip.text       = element_text(size=25, color = color.text, hjust = 0.5, vjust = 0.5,face = "bold", family = 'firasans')) +
    
    # Plot margins
    theme(plot.margin = unit(c(0.35, 0.2, 0.3, 0.35), "cm"))
}

Reading the Data

rent <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-07-05/rent.csv')
new_construction <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-07-05/new_construction.csv')

Rent

head(rent)

glimpse(rent)

rent %>%
count(year, sort = TRUE)%>%
arrange(year)

We have data from 2000 to 2018.

rent %>%
count(county, sort = TRUE)

There are total 10 counties.

Distribution of Price

rent %>%
ggplot(aes(x = price))+
geom_histogram(bins = 50, fill = "#8EE5EE")+
scale_x_log10()+
my_theme()+
labs(title = "Distribution of Price")

image

Distribution of Area

rent %>%
ggplot(aes(x = sqft))+
geom_histogram(bins = 50, fill = "#FF6A6A")+
scale_x_log10()+
my_theme()+
labs(title = "Distribution of Area in (sqft)")

image

Rental Prices According to No. of Bedrooms

rent %>%
filter(!is.na(beds))%>%
mutate(beds = as.factor(beds))%>%
ggplot(aes(year, price, color = beds))+
geom_jitter()+
scale_color_paletteer_d("DresdenColor::paired")+
my_theme()+
labs(title = "Rental Prices according to Number of Bedrooms")+
theme(legend.position = "top") +
theme(legend.key = element_rect(fill = "#030303"))+
theme(legend.text = element_text(size = 40, face = "bold", color = 'white'))+
theme(legend.justification = "center")+
theme(legend.title = element_text(family = "firasans",color = "white",size = 40, face = "bold"))+
theme(legend.key.size = unit(2, 'cm'))+
theme(legend.background = element_rect(fill = "transparent"))+
guides(color = guide_legend(override.aes = list(size = 10)))

image

Distribution Of Price According to County

rent %>%
filter(!is.na(county))%>%
ggplot(aes(price,county, fill = county))+
geom_density_ridges2()+
scale_x_log10()+
scale_fill_paletteer_d("DresdenColor::paired")+
my_theme()+
theme(legend.position = "none")+
labs(title = "Distribution of Price according to Counties")

image

Distribution Of Price According to Years.

rent %>%
mutate(year = as.factor(year))%>%
ggplot(aes(price,year, fill = year))+
geom_density_ridges2()+
scale_x_log10()+
scale_fill_paletteer_d("ggsci::category20c_d3")+
my_theme()+
theme(legend.position = "none")+
labs(title = "Distribution of Price over the years.")

image

Top 20 Cities

rent %>%
count(city, sort = TRUE)%>%
head(20)%>%
ggplot(aes(reorder(city, n),n, fill = city))+
geom_col()+
scale_fill_paletteer_d("ggsci::default_igv")+
coord_flip()+
my_theme()+
labs(title = "Top 20 Cities")+
theme(legend.position = "none")

image

Median Rent Prices According to Cities

rent %>%
filter(!is.na(city))%>%
group_by(city)%>%
summarise(med = median(price))%>%
arrange(desc(med))%>%
head(20)%>%
ggplot(aes(reorder(city, med),med, fill = city))+
geom_col()+
scale_fill_paletteer_d("ggsci::category20b_d3")+
geom_text(aes(label = med), size = 10, hjust = 2, fontface = "bold")+
coord_flip()+
my_theme()+
labs(title = "Median Prices according to City in (USD)")+
theme(legend.position = "none")+
theme(axis.title.y = element_blank())

image

New Constructions

head(new_construction)

glimpse(new_construction)

Total Production of New Construction

new_construction %>%
ggplot(aes(year, totalproduction, fill = county))+
geom_area()+
scale_fill_paletteer_d("DresdenColor::paired")+
my_theme()+
labs(title = 'Total Production of New Construction')+
theme(legend.position = "top") +
theme(legend.key = element_rect(fill = "#030303"))+
theme(legend.text = element_text(size = 20, face = "bold", color = 'white'))+
theme(legend.justification = "center")+
theme(legend.title = element_text(family = "firasans",color = "white",size = 20, face = "bold"))+
theme(legend.key.size = unit(1, 'cm'))+
theme(legend.background = element_rect(fill = "transparent"))+
guides(color = guide_legend(override.aes = list(size = 10)))

image

Single Family home New Production

new_construction %>%
ggplot(aes(year, sfproduction, fill = county))+
geom_area()+
scale_fill_paletteer_d("DresdenColor::paired")+
my_theme()+
labs(title = 'Production of Single Family Homes')+
theme(legend.position = "top") +
theme(legend.key = element_rect(fill = "#030303"))+
theme(legend.text = element_text(size = 20, face = "bold", color = 'white'))+
theme(legend.justification = "center")+
theme(legend.title = element_text(family = "firasans",color = "white",size = 20, face = "bold"))+
theme(legend.key.size = unit(1, 'cm'))+
theme(legend.background = element_rect(fill = "transparent"))+
guides(color = guide_legend(override.aes = list(size = 10)))

image

Multi family home Production

new_construction %>%
ggplot(aes(year, mfproduction, fill = county))+
geom_area()+
scale_fill_paletteer_d("DresdenColor::paired")+
my_theme()+
labs(title = 'Production of Multi Family Homes')+
theme(legend.position = "top") +
theme(legend.key = element_rect(fill = "#030303"))+
theme(legend.text = element_text(size = 20, face = "bold", color = 'white'))+
theme(legend.justification = "center")+
theme(legend.title = element_text(family = "firasans",color = "white",size = 20, face = "bold"))+
theme(legend.key.size = unit(1, 'cm'))+
theme(legend.background = element_rect(fill = "transparent"))+
guides(color = guide_legend(override.aes = list(size = 10)))

image

Production of Mobile Homes

new_construction %>%
ggplot(aes(year, mhproduction, fill = county))+
geom_area()+
scale_fill_paletteer_d("DresdenColor::paired")+
my_theme()+
labs(title = 'Production of Mobile Homes')+
theme(legend.position = 'right')+
theme(legend.position = "top") +
theme(legend.key = element_rect(fill = "#030303"))+
theme(legend.text = element_text(size = 20, face = "bold", color = 'white'))+
theme(legend.justification = "center")+
theme(legend.title = element_text(family = "firasans",color = "white",size = 20, face = "bold"))+
theme(legend.key.size = unit(1, 'cm'))+
theme(legend.background = element_rect(fill = "transparent"))+
guides(color = guide_legend(override.aes = list(size = 10)))

image