library(tidyverse)
library(tidycensus)
library(gapminder)
library(gt)
library(gtExtras)
library(scales)
Assignment 6
Open the assign06.qmd
file and complete the exercises.
This is a very open-ended assignment. There are three musts:
You must use the
tidycensus
package to get either decennial or ACS data from the US Census Bureau.You must get data for two different variables and they can’t be population or median home values.
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
This is your work area. Add as many code cells as you need.
# High school graduation rate (percentage)
<- get_acs(
hs_grad geography = "county",
variables = "S1501_C02_014",
state = "ME",
year = 2022,
survey = "acs5",
output = "wide"
)
Getting data from the 2018-2022 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.
Using the ACS Subject Tables
# Per capita income (dollars)
<- get_acs(
income geography = "county",
variables = "B19301_001",
state = "ME",
year = 2022,
survey = "acs5",
output = "wide"
)
Getting data from the 2018-2022 5-year ACS
<- hs_grad |>
hs_clean select(NAME, hs_grad_pct = S1501_C02_014E)
<- income |>
income_clean select(NAME, per_cap_income = B19301_001E)
<- hs_clean |>
combined inner_join(income_clean, by = "NAME") |>
mutate(
hs_grad_pct = round(hs_grad_pct, 1),
per_cap_income = round(per_cap_income, 0)
)
|>
combined gt() |>
tab_header(
title = "Education and Income in Maine Counties (ACS 2022)",
subtitle = "High School Graduation Rates and Per Capita Income"
|>
) fmt_percent(columns = hs_grad_pct, scale_values = FALSE) |>
fmt_currency(columns = per_cap_income) |>
cols_label(
NAME = "County",
hs_grad_pct = "High School Grad Rate",
per_cap_income = "Per Capita Income"
|>
) gt_theme_nytimes()
Education and Income in Maine Counties (ACS 2022) | ||
---|---|---|
High School Graduation Rates and Per Capita Income | ||
County | High School Grad Rate | Per Capita Income |
Androscoggin County, Maine | 92.00% | $34,273.00 |
Aroostook County, Maine | 90.60% | $31,001.00 |
Cumberland County, Maine | 96.30% | $51,405.00 |
Franklin County, Maine | 93.90% | $33,161.00 |
Hancock County, Maine | 95.00% | $38,785.00 |
Kennebec County, Maine | 94.60% | $36,009.00 |
Knox County, Maine | 93.70% | $39,379.00 |
Lincoln County, Maine | 94.80% | $43,436.00 |
Oxford County, Maine | 91.10% | $30,884.00 |
Penobscot County, Maine | 93.90% | $34,423.00 |
Piscataquis County, Maine | 92.00% | $32,843.00 |
Sagadahoc County, Maine | 94.30% | $40,950.00 |
Somerset County, Maine | 91.80% | $31,348.00 |
Waldo County, Maine | 93.20% | $35,677.00 |
Washington County, Maine | 90.90% | $30,731.00 |
York County, Maine | 94.70% | $42,053.00 |
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. |