Skip to content

Instantly share code, notes, and snippets.

@soodoku
Last active October 18, 2016 01:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soodoku/2e059b5cd93a7fb986b2bb21b7e7f9c8 to your computer and use it in GitHub Desktop.
Save soodoku/2e059b5cd93a7fb986b2bb21b7e7f9c8 to your computer and use it in GitHub Desktop.
Rent Control
# Read the data
sf <- read.csv("sf_tenants.csv")
# Recode
sf$market_rates <- gsub("%", "", sapply(strsplit(sf$market_rate, " / "), "[", 2)) # market_rate
sf$rent_control_rates <- gsub("%", "", sapply(strsplit(sf$rent_control, " / "), "[", 2)) # market_rate
# Ratio of rent_control vs. rent_control
sf$ratio <- as.numeric(sf$rent_control_rates)/as.numeric(sf$market_rates)
# Load libs
library(ggplot2)
# Custom Theme
cust_theme <-
theme_minimal() +
theme(panel.grid.major.x = element_blank(),
panel.grid.major.y = element_line(color="#e7e7e7", linetype = "dotted"),
panel.grid.minor = element_blank(),
legend.position ="none",
legend.key = element_blank(),
legend.key.width = unit(1,"cm"),
axis.title = element_text(size=10, color="#555555"),
axis.text = element_text(size=8, color="#555555"),
axis.ticks.y = element_blank(),
axis.title.x = element_text(vjust=-1),
axis.title.y = element_text(vjust= 1),
axis.ticks.x = element_line(color="#e3e3e3", size=.2),
plot.margin = unit(c(0,1,.5,.5), "cm"))
# Plot
ggplot(sf[1:5,], aes(x=Ethnicity, y=ratio)) +
geom_bar(stat="identity") +
xlab("") +
ylab("Ratio of Percent in Rent Control and Percent in Market Rates") +
cust_theme
ggsave("ratio.png")
# Two bars
# Plot
sf2 <- with(sf[1:5, ], data.frame(ethnicity = c(Ethnicity, Ethnicity), value = as.numeric(c(market_rates, rent_control_rates)), market_rent = c(rep("Market Rate", 5), rep("Rent Control", 5))))
ggplot(sf2, aes(x=ethnicity, y=value, fill=market_rent)) +
geom_bar(stat = "identity", width=.25, position="dodge") +
xlab("") +
ylab("Percent of Market Rate and Rent Control Apartments Occupied by Ethnicity") +
cust_theme
ggsave("two_bars.png")
Ethnicity all_units all_sf_renters_1998 market_rate rent_controlled subsidized_assisted
White 346 / 62% 134,669 / 63% 28 / 54% 280 / 72% 26 / 36%
African - American 47 / 8% 17,084 / 8% 5 / 10% 19 / 5% 18 / 25%
Latino 68 / 12% 23,068 / 11% 7 / 13% 31 / 8% 13 / 18%
Asian 18 / 9% 42,186 / 20% 6 / 12% 30 / 8% 4 / 6%
Pacific Islander 3 / 1% 793 / 0% 1 / 2% 2 / 1% 0 / 0%
Native American 2 / 0% 1,089 / 1% 2 / 4% 0 / 0% 0 / 0%
More than one of the above 24 / 4% 8,694 / 4% 2 / 4% 12 / 3% 8 / 11%
other 23 / 4% 9,794 / 5% 1 / 2% 14 / 4% 3 / 4%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment