This assignment is based on some of the basic methods presented in the Datacamp course on census data.

Setup

library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.3     v purrr   0.3.4
## v tibble  3.0.6     v dplyr   1.0.4
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(tidycensus)
library(scales)
## 
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
## 
##     discard
## The following object is masked from 'package:readr':
## 
##     col_factor

Problem 1

From the ACS questionnaire identify a topic that interests you. Copy the text of the question that produces the data you want and paste it here.

I will be using question 1 of Housing.

“Which best describes this building? Include all apartments, flats, etc., even if vacant”

Problem 2

Do a keyword search to find relevant variables in ACS5. Note that you can’t have View() in a knitted document. Use head() instead.

# Place your code here.

v19_5 = load_variables(year = 2019,"acs5",
                       cache = TRUE)

v19_5 %>% 
  filter(str_detect(str_to_lower(label),"20 to 49")) %>% 
  head()

Problem 3

Use get_acs() to obtain the values of your selected variable from the 2015-2019 file.

# Place your code here.

apartments20_49 <- get_acs(geography = "county", state="WA", variables = "B25024_008", geometry = TRUE) %>%
   mutate(NAME = str_replace(NAME," County, Washington",""))
## Getting data from the 2015-2019 5-year ACS
## Downloading feature geometry from the Census website.  To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
head(apartments20_49)

Problem 4

Do a dotplot of the variable you selected.

# Place your code here.

ggplot(apartments20_49, aes(x=reorder(NAME, estimate), y=estimate)) + 
  geom_point() + 
  labs(x = "County", y = "Num of Units in Apartment", title = "Total Number of Apartments with Between 20 and 49 Units") + 
  coord_flip()

Problem 5

Create a map for your variable using geom_sf()

# Place your code here.

ggplot(apartments20_49) +
  geom_sf(aes(fill = estimate)) +
  geom_sf_label(aes(label = NAME)) 
## Warning in st_point_on_surface.sfc(sf::st_zm(x)): st_point_on_surface may not
## give correct results for longitude/latitude data