Assignment 6

Author

Zachary Howe

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.

# Load libraries
library(tidycensus)
library(tidyverse)
library(gt)

# EDUCATION DATA
edu_vars <- c(
  "B15003_001", # Total pop 25+
  "B15003_022", # Bachelor's
  "B15003_023", # Master's
  "B15003_024", # Professional school
  "B15003_025"  # Doctorate
)

edu_data <- get_acs(
  geography = "county",
  state = "ME",
  variables = edu_vars,
  year = 2021,
  survey = "acs5"
)
Getting data from the 2017-2021 5-year ACS
Warning: • You have not set a Census API key. Users without a key are limited to 500
queries per day and may experience performance limitations.
ℹ For best results, get a Census API key at
http://api.census.gov/data/key_signup.html and then supply the key to the
`census_api_key()` function to use it throughout your tidycensus session.
This warning is displayed once per session.
edu_summary <- edu_data %>%
  filter(variable != "B15003_001") %>%
  group_by(GEOID, NAME) %>%
  summarise(total_deg = sum(estimate), .groups = "drop") %>%
  left_join(
    edu_data %>%
      filter(variable == "B15003_001") %>%
      select(GEOID, total = estimate),
    by = "GEOID"
  ) %>%
  mutate(pct_bachelors_or_higher = total_deg / total)

# POVERTY DATA — FIXED with named variables
poverty_vars <- c(
  total_poverty_universe = "B17001_001",  # Total population for poverty status
  below_poverty = "B17001_002"            # Number below poverty line
)

poverty_data <- get_acs(
  geography = "county",
  state = "ME",
  variables = poverty_vars,
  year = 2021,
  survey = "acs5",
  output = "wide"
) %>%
  mutate(
    number_below_poverty = below_povertyE  # Use the named column
  ) %>%
  select(GEOID, NAME, number_below_poverty)
Getting data from the 2017-2021 5-year ACS
# MERGE
merged_data <- edu_summary %>%
  left_join(poverty_data, by = c("GEOID", "NAME"))

# FINAL TABLE
merged_data %>%
  select(NAME, pct_bachelors_or_higher, number_below_poverty) %>%
  gt() %>%
  tab_header(
    title = "Maine Counties: Education vs Poverty",
    subtitle = "Bachelor’s degree or higher vs. number of people below poverty line"
  ) %>%
  fmt_percent(
    columns = pct_bachelors_or_higher,
    decimals = 1
  ) %>%
  fmt_number(
    columns = number_below_poverty,
    decimals = 0,
    use_seps = TRUE
  ) %>%
  cols_label(
    pct_bachelors_or_higher = "Bachelor's Degree or Higher (%)",
    number_below_poverty = "People Below Poverty Line"
  )
Maine Counties: Education vs Poverty
Bachelor’s degree or higher vs. number of people below poverty line
NAME Bachelor's Degree or Higher (%) People Below Poverty Line
Androscoggin County, Maine 22.9% 12,793
Aroostook County, Maine 20.3% 9,466
Cumberland County, Maine 49.8% 22,916
Franklin County, Maine 28.1% 3,367
Hancock County, Maine 35.5% 5,548
Kennebec County, Maine 29.7% 14,380
Knox County, Maine 36.3% 3,613
Lincoln County, Maine 37.6% 3,665
Oxford County, Maine 21.1% 7,990
Penobscot County, Maine 30.0% 20,031
Piscataquis County, Maine 20.3% 2,622
Sagadahoc County, Maine 38.2% 4,061
Somerset County, Maine 19.9% 8,866
Waldo County, Maine 32.9% 5,064
Washington County, Maine 24.0% 5,616
York County, Maine 32.8% 15,994

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.