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
readRenviron("~/.Renviron")new_england_states <-c("CT", "ME", "MA", "NH", "RI", "VT")ne_bachelors_female_birth <-get_acs(geography ="state",variables =c(bachelors_degree ="B15003_022", # People with bachelor's degreesteen_births ="B13002_003"# Teen births (ages 15–19) ),year =2020,survey ="acs5",state = new_england_states)saveRDS(ne_bachelors_female_birth, "ne_data_cached.rds")# Clean and reshape the datane_bachelors_female_birth <- ne_bachelors_female_birth |>select(GEOID, NAME, variable, estimate) |>pivot_wider(names_from = variable, values_from = estimate) |>rename(Bachelors_Degree = bachelors_degree,Teen_Births = teen_births)# Create a comparison tablecomparison_table <- ne_bachelors_female_birth |>select(NAME, Bachelors_Degree, Teen_Births)# Display the comparison table using gtcomparison_table |>gt() |>tab_header(title ="Comparison of Bachelor's Degree and Teen Births in New England States (2020)") |>fmt_number(columns =vars(Bachelors_Degree, Teen_Births),decimals =0) |>cols_label(Bachelors_Degree ="Bachelor's Degree",Teen_Births ="Teen Births")
Warning: Since gt v0.3.0, `columns = vars(...)` has been deprecated.
• Please use `columns = c(...)` instead.
Comparison of Bachelor's Degree and Teen Births in New England States (2020)
NAME
Bachelor's Degree
Teen Births
Connecticut
551,459
24,703
Maine
199,746
9,980
Massachusetts
1,181,453
52,773
New Hampshire
223,814
9,429
Rhode Island
155,981
7,568
Vermont
103,940
3,951
# Create a scatter plot to compare the two variablesggplot(comparison_table, aes(x = Bachelors_Degree, y = Teen_Births, label = NAME)) +geom_point(color ="blue", size =3) +geom_text(vjust =-0.5, hjust =0.5, size =3) +labs(title ="Bachelor's Degree vs. Teen Births in New England States (2020)",x ="Bachelor's Degree",y ="Teen Births" ) +theme_minimal()
This is your work area. Add as many code cells as you need.
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.