Dr. Kyle Walker TidyCensus Exercises, With Spatial

I am interested in seeing how many people that workin in the information sector work from home, by Michigan county.

load in packages

library(tidycensus)
library(tidyverse)
library(tigris)
library(mapview)
library(sf)

Census API key running here, but hidden

Use get_acs to gather number of people working in the information sector, by Michigan county, and working from home

workFromHome_information <- get_acs(
  geography = "county",
  variables = "B08126_098",
  state = "MI",
  year = 2022,
  survey = "acs5",
  geometry = TRUE
)
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |                                                                      |   1%
  |                                                                            
  |=                                                                     |   1%
  |                                                                            
  |=                                                                     |   2%
  |                                                                            
  |==                                                                    |   2%
  |                                                                            
  |==                                                                    |   3%
  |                                                                            
  |===                                                                   |   4%
  |                                                                            
  |===                                                                   |   5%
  |                                                                            
  |====                                                                  |   5%
  |                                                                            
  |====                                                                  |   6%
  |                                                                            
  |======                                                                |   8%
  |                                                                            
  |======                                                                |   9%
  |                                                                            
  |==========                                                            |  14%
  |                                                                            
  |===========                                                           |  16%
  |                                                                            
  |===============                                                       |  21%
  |                                                                            
  |===================                                                   |  27%
  |                                                                            
  |===================                                                   |  28%
  |                                                                            
  |====================                                                  |  28%
  |                                                                            
  |====================                                                  |  29%
  |                                                                            
  |=====================                                                 |  29%
  |                                                                            
  |======================                                                |  31%
  |                                                                            
  |======================                                                |  32%
  |                                                                            
  |=======================                                               |  32%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |========================                                              |  34%
  |                                                                            
  |=========================                                             |  36%
  |                                                                            
  |==========================                                            |  37%
  |                                                                            
  |============================                                          |  41%
  |                                                                            
  |=============================                                         |  42%
  |                                                                            
  |==============================                                        |  43%
  |                                                                            
  |===============================                                       |  44%
  |                                                                            
  |===============================                                       |  45%
  |                                                                            
  |=================================                                     |  46%
  |                                                                            
  |=================================                                     |  48%
  |                                                                            
  |=====================================                                 |  53%
  |                                                                            
  |======================================                                |  55%
  |                                                                            
  |=======================================                               |  56%
  |                                                                            
  |=========================================                             |  58%
  |                                                                            
  |==========================================                            |  61%
  |                                                                            
  |============================================                          |  63%
  |                                                                            
  |=============================================                         |  65%
  |                                                                            
  |================================================                      |  69%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |==================================================                    |  71%
  |                                                                            
  |===================================================                   |  73%
  |                                                                            
  |======================================================                |  77%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |=========================================================             |  82%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |============================================================          |  85%
  |                                                                            
  |=============================================================         |  87%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |==================================================================    |  94%
  |                                                                            
  |===================================================================   |  96%
  |                                                                            
  |======================================================================| 100%
workFromHome_information_total <- get_acs(
  geography = "county",
  variables = "B08526_008",
  state = "MI",
  year = 2022,
  survey = "acs5",
  geometry = TRUE
)

Simple map of the work from home data. The highest amount of information workers working from home is in urban counties near Detroit. However, that might not be as interesting as seeing the share of information workers working from home.

plot(workFromHome_information["estimate"])
Fig 1. Michigan counties by count of information workers that work from home.

Fig 1. Michigan counties by count of information workers that work from home.

Merge the two objects, create a new variable to calcualte the share share of those working from home in the information sector

#drop geometry from workFromHome_information
workFromHome_information <- st_drop_geometry(workFromHome_information)

#left join to workFromHome_information_share 
workFromHome_information_share <- workFromHome_information %>%
  left_join(workFromHome_information_total, by = "GEOID") %>%
  #create wfh_share column
  mutate(wfh_share = estimate.x / estimate.y) %>%
  #remove unneeded columns
  select(-ends_with(".x")) %>%
  #rename columns to be read easier
  rename_all(~sub("\\.y$", "", .))

#check object type of workFromHome_information_share 
class(workFromHome_information_share)
## [1] "data.frame"
#covert back to sf object
workFromHome_information_share <- st_as_sf(workFromHome_information_share)

#check object type of workFromHome_information_share 
class(workFromHome_information_share)
## [1] "sf"         "data.frame"

Interactive map of the work from home data

mapview(workFromHome_information_share, zcol = "wfh_share")

Choropleth map of the share of information workers that work from home

ggplot(workFromHome_information_share, aes(fill = wfh_share)) + 
  geom_sf() + 
  theme_void() + 
  scale_fill_viridis_b(option = "rocket", n.breaks = 6) + 
  labs(title = "Share of Information Workers that Work From Home",
       subtitle = "Michigan Counties",
       fill = "Work From Home Share",
       caption = "2018-2022 ACS | tidycensus R package")
Fig 3. Michigan counties by share of information workers that work from home, choropleth map.

Fig 3. Michigan counties by share of information workers that work from home, choropleth map.

The share of information workers working from home is higher in rural counties comapres to the actual count of informaiton workers working from home. This is likley do the a smaller amount of information workers in those rural counties, compared to the urban counties near Detroit.