Assignment 6

Author

Grace-Ann Walker

Go to the shared posit.cloud workspace for this class and open the assign06 project. Open the assign06.qmd file and complete the exercises.

This is a very open-ended assignment. There are three musts:

  1. You must use the tidycensus package to get either decennial or ACS data from the US Census Bureau.

  2. You must get data for two different variables and they can’t be population or median home values.

  3. You must show all the code you used to get the data and create the table or chart.

You can then either create a cool table or chart comparing the two variables. They can be from any region and for any geography…it doesn’t necessarily need to be Maine.

Note: you will receive deductions for not using tidyverse syntax in this assignment. That includes the use of filter, mutate, and the up-to-date pipe operator |>.

The Grading Rubric is available at the end of this document.

We’ll preload the following potentially useful packages

library(tidyverse)
library(tidycensus)
library(gapminder)
library(gt)
library(gtExtras)
library(scales)

This is your work area. Add as many code cells as you need.

library(tidyverse)
library(tidycensus)
census_api_key("ef43e7e0e54b984a7a8d72886792c3b6d60d4cdd", overwrite = TRUE, install = TRUE)
Your original .Renviron will be backed up and stored in your R HOME directory if needed.
Your API key has been stored in your .Renviron and can be accessed by Sys.getenv("CENSUS_API_KEY"). 
To use now, restart R or run `readRenviron("~/.Renviron")`
[1] "ef43e7e0e54b984a7a8d72886792c3b6d60d4cdd"
readRenviron("~/.Renviron")
v20_acs5 <- load_variables(2020, "acs5", cache = TRUE)
glimpse(v20_acs5)
Rows: 27,850
Columns: 4
$ name      <chr> "B01001A_001", "B01001A_002", "B01001A_003", "B01001A_004", …
$ label     <chr> "Estimate!!Total:", "Estimate!!Total:!!Male:", "Estimate!!To…
$ concept   <chr> "SEX BY AGE (WHITE ALONE)", "SEX BY AGE (WHITE ALONE)", "SEX…
$ geography <chr> "tract", "tract", "tract", "tract", "tract", "tract", "tract…
library(gt)
v20_acs5 |> 
  filter(grepl("Income", label)) |> 
  head() |> 
  gt()
name label concept geography
B09010_002 Estimate!!Total:!!Living in household with Supplemental Security Income (SSI), cash public assistance income, or Food Stamps/SNAP in the past 12 months: RECEIPT OF SUPPLEMENTAL SECURITY INCOME (SSI), CASH PUBLIC ASSISTANCE INCOME, OR FOOD STAMPS/SNAP IN THE PAST 12 MONTHS BY HOUSEHOLD TYPE FOR CHILDREN UNDER 18 YEARS IN HOUSEHOLDS tract
B09010_003 Estimate!!Total:!!Living in household with Supplemental Security Income (SSI), cash public assistance income, or Food Stamps/SNAP in the past 12 months:!!In family households: RECEIPT OF SUPPLEMENTAL SECURITY INCOME (SSI), CASH PUBLIC ASSISTANCE INCOME, OR FOOD STAMPS/SNAP IN THE PAST 12 MONTHS BY HOUSEHOLD TYPE FOR CHILDREN UNDER 18 YEARS IN HOUSEHOLDS tract
B09010_004 Estimate!!Total:!!Living in household with Supplemental Security Income (SSI), cash public assistance income, or Food Stamps/SNAP in the past 12 months:!!In family households:!!In married-couple family RECEIPT OF SUPPLEMENTAL SECURITY INCOME (SSI), CASH PUBLIC ASSISTANCE INCOME, OR FOOD STAMPS/SNAP IN THE PAST 12 MONTHS BY HOUSEHOLD TYPE FOR CHILDREN UNDER 18 YEARS IN HOUSEHOLDS tract
B09010_005 Estimate!!Total:!!Living in household with Supplemental Security Income (SSI), cash public assistance income, or Food Stamps/SNAP in the past 12 months:!!In family households:!!In male householder, no spouse present, family RECEIPT OF SUPPLEMENTAL SECURITY INCOME (SSI), CASH PUBLIC ASSISTANCE INCOME, OR FOOD STAMPS/SNAP IN THE PAST 12 MONTHS BY HOUSEHOLD TYPE FOR CHILDREN UNDER 18 YEARS IN HOUSEHOLDS tract
B09010_006 Estimate!!Total:!!Living in household with Supplemental Security Income (SSI), cash public assistance income, or Food Stamps/SNAP in the past 12 months:!!In family households:!!In female householder, no spouse present, family RECEIPT OF SUPPLEMENTAL SECURITY INCOME (SSI), CASH PUBLIC ASSISTANCE INCOME, OR FOOD STAMPS/SNAP IN THE PAST 12 MONTHS BY HOUSEHOLD TYPE FOR CHILDREN UNDER 18 YEARS IN HOUSEHOLDS tract
B09010_007 Estimate!!Total:!!Living in household with Supplemental Security Income (SSI), cash public assistance income, or Food Stamps/SNAP in the past 12 months:!!In nonfamily households RECEIPT OF SUPPLEMENTAL SECURITY INCOME (SSI), CASH PUBLIC ASSISTANCE INCOME, OR FOOD STAMPS/SNAP IN THE PAST 12 MONTHS BY HOUSEHOLD TYPE FOR CHILDREN UNDER 18 YEARS IN HOUSEHOLDS tract
v22_acs5 <- load_variables(2020, "acs5", cache = TRUE)
Sup_Income_Receipt <- get_acs(
  geography = "county subdivision",
  variables = "B09010_003",
  state = "ME",
  county = "York",
  year = 2020
)
Getting data from the 2016-2020 5-year ACS
Sup_Income_Receipt |> gt()
GEOID NAME variable estimate moe
2303100275 Acton town, York County, Maine B09010_003 147 90
2303100730 Alfred town, York County, Maine B09010_003 13 20
2303101605 Arundel town, York County, Maine B09010_003 119 73
2303104720 Berwick town, York County, Maine B09010_003 37 43
2303104860 Biddeford city, York County, Maine B09010_003 1086 267
2303109410 Buxton town, York County, Maine B09010_003 165 116
2303114485 Cornish town, York County, Maine B09010_003 62 51
2303116725 Dayton town, York County, Maine B09010_003 101 48
2303122955 Eliot town, York County, Maine B09010_003 194 136
2303133665 Hollis town, York County, Maine B09010_003 9 14
2303136535 Kennebunk town, York County, Maine B09010_003 383 255
2303136745 Kennebunkport town, York County, Maine B09010_003 0 11
2303137270 Kittery town, York County, Maine B09010_003 194 105
2303138425 Lebanon town, York County, Maine B09010_003 119 88
2303139195 Limerick town, York County, Maine B09010_003 65 37
2303139405 Limington town, York County, Maine B09010_003 79 63
2303141750 Lyman town, York County, Maine B09010_003 0 11
2303148750 Newfield town, York County, Maine B09010_003 110 65
2303150325 North Berwick town, York County, Maine B09010_003 169 148
2303154980 Ogunquit town, York County, Maine B09010_003 0 11
2303155085 Old Orchard Beach town, York County, Maine B09010_003 10 16
2303156870 Parsonsfield town, York County, Maine B09010_003 121 79
2303164675 Saco city, York County, Maine B09010_003 800 306
2303165725 Sanford city, York County, Maine B09010_003 1504 407
2303167475 Shapleigh town, York County, Maine B09010_003 99 61
2303170030 South Berwick town, York County, Maine B09010_003 57 64
2303180530 Waterboro town, York County, Maine B09010_003 141 177
2303181475 Wells town, York County, Maine B09010_003 523 279
2303187985 York town, York County, Maine B09010_003 172 154
library(scales)
Sup_Income_Receipt |> 
  mutate(town = str_remove(NAME, " town, York County, Maine| city, York County, Maine" )) |>
  select(town, Sup_Income_Receipt = estimate) |> 
  ggplot(aes(x = Sup_Income_Receipt, y = fct_reorder(town, Sup_Income_Receipt))) + 
  geom_col() +
  labs(
    title = "Suplemental Income for York County",
    x = "Suplemental Income Received",
    y = "Town"
  ) +
  theme_minimal()

Submission

To submit your assignment:

  • Change the author name to your name in the YAML portion at the top of this document
  • Render your document to html and publish it to RPubs.
  • Submit the link to your Rpubs document in the Brightspace comments section for this assignment.
  • Click on the “Add a File” button and upload your .qmd file for this assignment to Brightspace.

Grading Rubric

Item
(percent overall)
100% - flawless 67% - minor issues 33% - moderate issues 0% - major issues or not attempted
Chart or table accuracy.
(45%)
No errors, good labels, everything is clearly visible in the rendered document.
At least two valid variables used from US census data (can be census or ACS)
(40%)
Messages and/or errors suppressed from rendered document and all code is shown.
(7%)
Submitted properly to Brightspace
(8%)
NA NA You must submit according to instructions to receive any credit for this portion.