Florida Home Vacancy Plot

Load Libraries

library(tidycensus)
library(tidyverse)

Be sure to get a census api key!

Data Gathering

Here, we grab total housing units and total vacant housing units in each state.

vars_2020 <- c(total_housing_units = "H1_001N",
               total_vacant = "H1_003N")

fl_housing_data <- get_decennial(geography = "county", 
                                 state = "FL", 
                                 variables = vars_2020, 
                                 geometry = TRUE,
                                 year = 2020) 

Code Widening

We widen the code to make analysis simpler since each variable is now a column associated with a county. We also add a column to measure the percent of vacant homes in each state.

fl_housing_data <- fl_housing_data |>
  pivot_wider(names_from = variable, values_from = value) |>
  mutate(percent_vacant = (total_vacant / total_housing_units) * 100)

Plot

We plot the percent of vacant homes for each Florida county using ggplot.

fl_housing_data |>
  ggplot(aes(fill = percent_vacant)) + 
  geom_sf(color = NA) + 
  scale_fill_viridis_c(option = "magma")