Introduction

This lab follows an analytic workshop for manipulating U.S. census data in R, hosted by The University of Michigan. The workshop is lead by Dr. Kyle Walker and primarily focuses on American Community Survey census data.

Lesson 5 Part A

In Part A I explored non-spatial concepts presented by Dr. Walker for census variable DP02_0066P, population percentage with graduate degree, in the state of Wyoming down to the county level resolution.

#load libraries

library(tidyverse)
library(tidycensus)

Data Preparation

# narrow results to one state (Wyoming)
WY_per_grad <- get_acs(
  geography = "county", 
  variables = "DP02_0066P", 
  state = "WY", #<<
  year = 2021
)
## Getting data from the 2017-2021 5-year ACS
## Using the ACS Data Profile
# determine county with lowest percentage 
arrange(WY_per_grad, estimate)
## # A tibble: 23 × 5
##    GEOID NAME                       variable   estimate   moe
##    <chr> <chr>                      <chr>         <dbl> <dbl>
##  1 56011 Crook County, Wyoming      DP02_0066P      3.6   1.4
##  2 56027 Niobrara County, Wyoming   DP02_0066P      3.9   2.1
##  3 56007 Carbon County, Wyoming     DP02_0066P      4.4   1.2
##  4 56045 Weston County, Wyoming     DP02_0066P      4.5   1.8
##  5 56041 Uinta County, Wyoming      DP02_0066P      5.6   1.5
##  6 56035 Sublette County, Wyoming   DP02_0066P      5.7   2.1
##  7 56003 Big Horn County, Wyoming   DP02_0066P      6.6   1.6
##  8 56037 Sweetwater County, Wyoming DP02_0066P      7     1.2
##  9 56023 Lincoln County, Wyoming    DP02_0066P      7.2   1.7
## 10 56005 Campbell County, Wyoming   DP02_0066P      7.4   1.6
## # ℹ 13 more rows
# determine county with highest percentage
arrange(WY_per_grad, desc(estimate))
## # A tibble: 23 × 5
##    GEOID NAME                     variable   estimate   moe
##    <chr> <chr>                    <chr>         <dbl> <dbl>
##  1 56001 Albany County, Wyoming   DP02_0066P     27.8   2.4
##  2 56039 Teton County, Wyoming    DP02_0066P     19.6   3.2
##  3 56019 Johnson County, Wyoming  DP02_0066P     14.1   4.1
##  4 56033 Sheridan County, Wyoming DP02_0066P     13.2   1.8
##  5 56031 Platte County, Wyoming   DP02_0066P     11.7   3.1
##  6 56021 Laramie County, Wyoming  DP02_0066P     11.4   1.1
##  7 56029 Park County, Wyoming     DP02_0066P     11     2  
##  8 56013 Fremont County, Wyoming  DP02_0066P      9.5   1.3
##  9 56009 Converse County, Wyoming DP02_0066P      9.4   2.3
## 10 56025 Natrona County, Wyoming  DP02_0066P      9.2   0.9
## # ℹ 13 more rows
# plot ACS estimate value with error bars
my_plot_errorbar <- ggplot(WY_per_grad, aes(x = estimate, 
                                            y = reorder(NAME, estimate))) + 
  geom_errorbar(aes(xmin = estimate - moe, xmax = estimate + moe),
                width = 0.5, linewidth = 0.5) +
  geom_point(color = "darkred", size = 2) + 
  scale_x_continuous() +
  scale_y_discrete(labels = function(x) str_remove(x, " County, Wyoming")) +
  labs(title = "Percentage of Graduate Degree Holders \n Wyoming",
       subtitle = "Counties in Wyoming",
       caption = "Data acquired with R and tidycensus. Error bars represent margin of error around estimates.",
       x = "2017-2021 ACS estimate \n[In percent (%)] ",
       y = "") + 
  theme_minimal(base_size = 12)

# display plot
my_plot_errorbar


Figure 1.) A point plot for graduate degree percentages. Here the error bar technique is used to show margin of error values from within the census data. Error plots show range comparison between estimated values.


# create interactive plot
library(plotly)

ggplotly(my_plot_errorbar, tooltip = "x")


Figure 2.) Here the plotly library is used to create an interactive replica of the plot in figure 1.


Analysis

A review of ACS data for percent population with a graduate level degree shows the following counties in Wyoming having the largest rates:
1. Albany County
2. Teton County
3. Johnson County
4. Sheridan County
5. Platte County

Wyoming counties with the smallest population percentage holding a graduate level degree include:
1. Crook County
2. Niobrara County
3. Carbon County
4. Weston County
5. Uinta County

For my margin of error plot, I selected the state of Wyoming. This technique proved effective in visualizing ACS estimates. For example, the error plot illustrates that the high-ranking county of Platte may in fact fall below the population percentage in Fremont county.

Lesson 5 Part B

In Part B I explored spatial concepts presented by Dr. Walker for census variable B25061_001, estimated total for rent asked, in the state of South Dakota down to the county level resolution.

#load additional libraries

library(mapview)
library(viridisLite)

Data Preparation

# search variables from 5yr ACS
Vars <- load_variables(2021, "acs5")

# 'Estimated total for rent asked' was selected

# Select county lvl rent data for South Dakota
sd_rent_asked <- get_acs(
  geography = "county",
  variables = "B25061_001",
  state = "SD",
  year = 2021,
  geometry = TRUE
)
##   |                                                                              |                                                                      |   0%  |                                                                              |                                                                      |   1%  |                                                                              |=                                                                     |   1%  |                                                                              |=                                                                     |   2%  |                                                                              |==                                                                    |   2%  |                                                                              |==                                                                    |   3%  |                                                                              |===                                                                   |   4%  |                                                                              |===                                                                   |   5%  |                                                                              |====                                                                  |   5%  |                                                                              |====                                                                  |   6%  |                                                                              |=====                                                                 |   7%  |                                                                              |=====                                                                 |   8%  |                                                                              |======                                                                |   8%  |                                                                              |======                                                                |   9%  |                                                                              |=======                                                               |   9%  |                                                                              |=======                                                               |  10%  |                                                                              |=======                                                               |  11%  |                                                                              |========                                                              |  11%  |                                                                              |========                                                              |  12%  |                                                                              |=========                                                             |  12%  |                                                                              |=========                                                             |  13%  |                                                                              |==========                                                            |  14%  |                                                                              |==========                                                            |  15%  |                                                                              |===========                                                           |  15%  |                                                                              |===========                                                           |  16%  |                                                                              |============                                                          |  17%  |                                                                              |============                                                          |  18%  |                                                                              |=============                                                         |  18%  |                                                                              |=============                                                         |  19%  |                                                                              |==============                                                        |  19%  |                                                                              |==============                                                        |  20%  |                                                                              |==============                                                        |  21%  |                                                                              |===============                                                       |  21%  |                                                                              |===============                                                       |  22%  |                                                                              |================                                                      |  22%  |                                                                              |================                                                      |  23%  |                                                                              |=================                                                     |  24%  |                                                                              |=================                                                     |  25%  |                                                                              |==================                                                    |  25%  |                                                                              |==================                                                    |  26%  |                                                                              |===================                                                   |  26%  |                                                                              |===================                                                   |  27%  |                                                                              |====================                                                  |  28%  |                                                                              |====================                                                  |  29%  |                                                                              |=====================                                                 |  30%  |                                                                              |======================                                                |  31%  |                                                                              |======================                                                |  32%  |                                                                              |=======================                                               |  32%  |                                                                              |=======================                                               |  33%  |                                                                              |========================                                              |  34%  |                                                                              |========================                                              |  35%  |                                                                              |=========================                                             |  35%  |                                                                              |=========================                                             |  36%  |                                                                              |==========================                                            |  37%  |                                                                              |==========================                                            |  38%  |                                                                              |===========================                                           |  38%  |                                                                              |===========================                                           |  39%  |                                                                              |============================                                          |  40%  |                                                                              |=============================                                         |  41%  |                                                                              |=============================                                         |  42%  |                                                                              |==============================                                        |  43%  |                                                                              |===============================                                       |  44%  |                                                                              |===============================                                       |  45%  |                                                                              |================================                                      |  45%  |                                                                              |================================                                      |  46%  |                                                                              |=================================                                     |  47%  |                                                                              |=================================                                     |  48%  |                                                                              |==================================                                    |  48%  |                                                                              |==================================                                    |  49%  |                                                                              |===================================                                   |  50%  |                                                                              |===================================                                   |  51%  |                                                                              |====================================                                  |  51%  |                                                                              |====================================                                  |  52%  |                                                                              |=====================================                                 |  52%  |                                                                              |=====================================                                 |  53%  |                                                                              |======================================                                |  54%  |                                                                              |======================================                                |  55%  |                                                                              |=======================================                               |  55%  |                                                                              |=======================================                               |  56%  |                                                                              |========================================                              |  57%  |                                                                              |========================================                              |  58%  |                                                                              |=========================================                             |  58%  |                                                                              |=========================================                             |  59%  |                                                                              |==========================================                            |  59%  |                                                                              |==========================================                            |  60%  |                                                                              |==========================================                            |  61%  |                                                                              |===========================================                           |  61%  |                                                                              |===========================================                           |  62%  |                                                                              |============================================                          |  63%  |                                                                              |=============================================                         |  64%  |                                                                              |=============================================                         |  65%  |                                                                              |==============================================                        |  65%  |                                                                              |==============================================                        |  66%  |                                                                              |===============================================                       |  67%  |                                                                              |===============================================                       |  68%  |                                                                              |================================================                      |  68%  |                                                                              |================================================                      |  69%  |                                                                              |=================================================                     |  69%  |                                                                              |=================================================                     |  70%  |                                                                              |==================================================                    |  71%  |                                                                              |==================================================                    |  72%  |                                                                              |===================================================                   |  73%  |                                                                              |====================================================                  |  74%  |                                                                              |====================================================                  |  75%  |                                                                              |=====================================================                 |  75%  |                                                                              |=====================================================                 |  76%  |                                                                              |======================================================                |  77%  |                                                                              |======================================================                |  78%  |                                                                              |=======================================================               |  78%  |                                                                              |=======================================================               |  79%  |                                                                              |========================================================              |  79%  |                                                                              |========================================================              |  80%  |                                                                              |=========================================================             |  81%  |                                                                              |=========================================================             |  82%  |                                                                              |==========================================================            |  82%  |                                                                              |==========================================================            |  83%  |                                                                              |===========================================================           |  84%  |                                                                              |============================================================          |  85%  |                                                                              |============================================================          |  86%  |                                                                              |=============================================================         |  87%  |                                                                              |==============================================================        |  88%  |                                                                              |==============================================================        |  89%  |                                                                              |===============================================================       |  90%  |                                                                              |================================================================      |  91%  |                                                                              |================================================================      |  92%  |                                                                              |=================================================================     |  93%  |                                                                              |==================================================================    |  94%  |                                                                              |===================================================================   |  95%  |                                                                              |===================================================================   |  96%  |                                                                              |====================================================================  |  97%  |                                                                              |===================================================================== |  98%  |                                                                              |===================================================================== |  99%  |                                                                              |======================================================================| 100%

#create interactive map

# map the selected data. Add zcol for default color ramp
mapview(sd_rent_asked, zcol = "estimate")


Figure 3.) An interactive map of total rent asked by county in South Dakota. The data is visualized using the mapview library.

#choropleth map

# create choropleth map of ACS estimated rent prices
ggplot(sd_rent_asked, aes(fill = estimate)) + 
  geom_sf() + 
  theme_void() + 
  scale_fill_viridis_c(option = "plasma") +
  labs(title = "Estimated Total Rent Asked",
       subtitle = "South Dakota Counties",
       fill = "ACS estimate \n[In Dollars ($)]",
       caption = "2017-2021 ACS | tidycensus R package")


Figure 4.) A choropleth map created with the ggplot library displaying estimated rent prices for each county in the state of South Dakota. Here the blue to yellow “plasma” scale from the viridisLite library was used to show variation.

Analysis

Analysis of the interactive and static maps of estimated rent prices in South Dakota identified Minnehaha County, near Sioux Falls, as having the highest rent prices at just over $2,000.