Assignment 6

Author

DaQuan Lindsey

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.

census_api_key("588c59e28c3267cfef86841afb142e9a0969544a", 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] "588c59e28c3267cfef86841afb142e9a0969544a"
variable <- load_variables(2020, "acs5", cache = TRUE) 
head(variable)
# A tibble: 6 × 4
  name        label                                   concept          geography
  <chr>       <chr>                                   <chr>            <chr>    
1 B01001A_001 Estimate!!Total:                        SEX BY AGE (WHI… tract    
2 B01001A_002 Estimate!!Total:!!Male:                 SEX BY AGE (WHI… tract    
3 B01001A_003 Estimate!!Total:!!Male:!!Under 5 years  SEX BY AGE (WHI… tract    
4 B01001A_004 Estimate!!Total:!!Male:!!5 to 9 years   SEX BY AGE (WHI… tract    
5 B01001A_005 Estimate!!Total:!!Male:!!10 to 14 years SEX BY AGE (WHI… tract    
6 B01001A_006 Estimate!!Total:!!Male:!!15 to 17 years SEX BY AGE (WHI… tract    
education_vars <- variable |>
  filter(str_detect(label, "education"))
head(education_vars)
# A tibble: 6 × 4
  name       label                                             concept geography
  <chr>      <chr>                                             <chr>   <chr>    
1 B24114_147 Estimate!!Total:!!Directors, religious activitie… DETAIL… us       
2 B24114_159 Estimate!!Total:!!Special education teachers      DETAIL… us       
3 B24114_166 Estimate!!Total:!!Other educational instruction … DETAIL… us       
4 B24115_147 Estimate!!Total:!!Directors, religious activitie… DETAIL… us       
5 B24115_159 Estimate!!Total:!!Special education teachers      DETAIL… us       
6 B24115_166 Estimate!!Total:!!Other educational instruction … DETAIL… us       
income_vars <- variable |>
  filter(str_detect(label, "income"))
view(income_vars)
education_data <- get_acs(
  geography = "state",
  variables = c("B15003_001E"),
  year = 2020)
Getting data from the 2016-2020 5-year ACS
income_data <- get_acs(
  geography = "state",
variable = c("B19013_001E"),
year = 2020)
Getting data from the 2016-2020 5-year ACS
education_data_clean <- education_data %>%
  select(GEOID, NAME, estimate) %>%
  rename(education_estimate = estimate) %>%
  mutate(variable = "Educational Attainment (Bachelor's Degree or Higher)")
income_data_clean <- income_data %>%
  select(GEOID, NAME, estimate) %>%
  rename(income_estimate = estimate) %>%
  mutate(variable = "Median Household Income")
combined_data <- left_join(education_data_clean, income_data_clean, by = c("GEOID", "NAME"))
ggplot(combined_data, aes(x = education_estimate, y = income_estimate)) +
  geom_point(aes(color = NAME), size = 3) +
  theme_minimal() +
  labs(
    title = "Comparison of Educational Attainment and Median Household Income by State",
    x = "Educational Attainment (Bachelor's Degree or Higher)",
    y = "Median Household Income (USD)"
  )

combined_data %>%
  gt() %>%
  tab_header(
    title = "State Comparison: Education and Income"
  ) %>%
  cols_label(
    NAME = "State",
    education_estimate = "Educational Attainment (%)",
    income_estimate = "Median Household Income (USD)"
  ) %>%
  fmt_number(
    columns = vars(education_estimate, income_estimate),
    decimals = 0
  )
Warning: Since gt v0.3.0, `columns = vars(...)` has been deprecated.
• Please use `columns = c(...)` instead.
State Comparison: Education and Income
GEOID State Educational Attainment (%) variable.x Median Household Income (USD) variable.y
01 Alabama 3,344,006 Educational Attainment (Bachelor's Degree or Higher) 52,035 Median Household Income
02 Alaska 483,436 Educational Attainment (Bachelor's Degree or Higher) 77,790 Median Household Income
04 Arizona 4,846,056 Educational Attainment (Bachelor's Degree or Higher) 61,529 Median Household Income
05 Arkansas 2,026,722 Educational Attainment (Bachelor's Degree or Higher) 49,475 Median Household Income
06 California 26,665,143 Educational Attainment (Bachelor's Degree or Higher) 78,672 Median Household Income
08 Colorado 3,900,754 Educational Attainment (Bachelor's Degree or Higher) 75,231 Median Household Income
09 Connecticut 2,489,205 Educational Attainment (Bachelor's Degree or Higher) 79,855 Median Household Income
10 Delaware 679,870 Educational Attainment (Bachelor's Degree or Higher) 69,110 Median Household Income
11 District of Columbia 501,986 Educational Attainment (Bachelor's Degree or Higher) 90,842 Median Household Income
12 Florida 15,255,326 Educational Attainment (Bachelor's Degree or Higher) 57,703 Median Household Income
13 Georgia 6,996,425 Educational Attainment (Bachelor's Degree or Higher) 61,224 Median Household Income
15 Hawaii 996,423 Educational Attainment (Bachelor's Degree or Higher) 83,173 Median Household Income
16 Idaho 1,145,344 Educational Attainment (Bachelor's Degree or Higher) 58,915 Median Household Income
17 Illinois 8,686,700 Educational Attainment (Bachelor's Degree or Higher) 68,428 Median Household Income
18 Indiana 4,466,180 Educational Attainment (Bachelor's Degree or Higher) 58,235 Median Household Income
19 Iowa 2,104,864 Educational Attainment (Bachelor's Degree or Higher) 61,836 Median Household Income
20 Kansas 1,911,990 Educational Attainment (Bachelor's Degree or Higher) 61,091 Median Household Income
21 Kentucky 3,034,491 Educational Attainment (Bachelor's Degree or Higher) 52,238 Median Household Income
22 Louisiana 3,139,520 Educational Attainment (Bachelor's Degree or Higher) 50,800 Median Household Income
23 Maine 982,385 Educational Attainment (Bachelor's Degree or Higher) 59,489 Median Household Income
24 Maryland 4,164,698 Educational Attainment (Bachelor's Degree or Higher) 87,063 Median Household Income
25 Massachusetts 4,815,331 Educational Attainment (Bachelor's Degree or Higher) 84,385 Median Household Income
26 Michigan 6,853,674 Educational Attainment (Bachelor's Degree or Higher) 59,234 Median Household Income
27 Minnesota 3,802,438 Educational Attainment (Bachelor's Degree or Higher) 73,382 Median Household Income
28 Mississippi 1,983,112 Educational Attainment (Bachelor's Degree or Higher) 46,511 Median Household Income
29 Missouri 4,176,792 Educational Attainment (Bachelor's Degree or Higher) 57,290 Median Household Income
30 Montana 734,688 Educational Attainment (Bachelor's Degree or Higher) 56,539 Median Household Income
31 Nebraska 1,259,540 Educational Attainment (Bachelor's Degree or Higher) 63,015 Median Household Income
32 Nevada 2,093,820 Educational Attainment (Bachelor's Degree or Higher) 62,043 Median Household Income
33 New Hampshire 971,162 Educational Attainment (Bachelor's Degree or Higher) 77,923 Median Household Income
34 New Jersey 6,169,501 Educational Attainment (Bachelor's Degree or Higher) 85,245 Median Household Income
35 New Mexico 1,415,298 Educational Attainment (Bachelor's Degree or Higher) 51,243 Median Household Income
36 New York 13,649,157 Educational Attainment (Bachelor's Degree or Higher) 71,117 Median Household Income
37 North Carolina 7,096,773 Educational Attainment (Bachelor's Degree or Higher) 56,642 Median Household Income
38 North Dakota 497,525 Educational Attainment (Bachelor's Degree or Higher) 65,315 Median Household Income
39 Ohio 8,014,966 Educational Attainment (Bachelor's Degree or Higher) 58,116 Median Household Income
40 Oklahoma 2,611,680 Educational Attainment (Bachelor's Degree or Higher) 53,840 Median Household Income
41 Oregon 2,944,830 Educational Attainment (Bachelor's Degree or Higher) 65,667 Median Household Income
42 Pennsylvania 8,989,998 Educational Attainment (Bachelor's Degree or Higher) 63,627 Median Household Income
44 Rhode Island 741,370 Educational Attainment (Bachelor's Degree or Higher) 70,305 Median Household Income
45 South Carolina 3,512,626 Educational Attainment (Bachelor's Degree or Higher) 54,864 Median Household Income
46 South Dakota 580,244 Educational Attainment (Bachelor's Degree or Higher) 59,896 Median Household Income
47 Tennessee 4,649,847 Educational Attainment (Bachelor's Degree or Higher) 54,833 Median Household Income
48 Texas 18,449,851 Educational Attainment (Bachelor's Degree or Higher) 63,826 Median Household Income
49 Utah 1,868,472 Educational Attainment (Bachelor's Degree or Higher) 74,197 Median Household Income
50 Vermont 442,089 Educational Attainment (Bachelor's Degree or Higher) 63,477 Median Household Income
51 Virginia 5,831,949 Educational Attainment (Bachelor's Degree or Higher) 76,398 Median Household Income
53 Washington 5,199,771 Educational Attainment (Bachelor's Degree or Higher) 77,006 Median Household Income
54 West Virginia 1,283,869 Educational Attainment (Bachelor's Degree or Higher) 48,037 Median Household Income
55 Wisconsin 3,982,118 Educational Attainment (Bachelor's Degree or Higher) 63,293 Median Household Income
56 Wyoming 392,819 Educational Attainment (Bachelor's Degree or Higher) 65,304 Median Household Income
72 Puerto Rico 2,331,294 Educational Attainment (Bachelor's Degree or Higher) 21,058 Median Household Income

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.