library(tidyverse)
library(tidycensus)
library(gapminder)
library(gt)
library(gtExtras)
library(scales)Assignment 6
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:
You must use the
tidycensuspackage 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.
maine_occupied_2020 <- get_decennial(
geography = "county",
state = "Maine",
year = 2020,
variables = "H1_002N",
sumfile = "pl"
)Getting data from the 2020 decennial Census
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 PL 94-171 Redistricting Data Summary File
Note: 2020 decennial Census data use differential privacy, a technique that
introduces errors into data to preserve respondent confidentiality.
ℹ Small counts should be interpreted with caution.
ℹ See https://www.census.gov/library/fact-sheets/2021/protecting-the-confidentiality-of-the-2020-census-redistricting-data.html for additional guidance.
This message is displayed once per session.
maine_vacant_2020 <- get_decennial(
geography = "county",
state = "Maine",
year = 2020,
variables = "H1_003N",
sumfile = "pl"
)Getting data from the 2020 decennial Census
Using the PL 94-171 Redistricting Data Summary File
maine_unit_occupancy_2020 <- maine_occupied_2020 |>
union(maine_vacant_2020)
maine_unit_occupancy_2020 <- maine_unit_occupancy_2020 |>
mutate(variable = replace(variable, variable == "H1_002N", "Occupied")) |>
mutate(variable = replace(variable, variable == "H1_003N", "Vacant"))
maine_unit_occupancy_2020 |>
gt()| GEOID | NAME | variable | value |
|---|---|---|---|
| 23001 | Androscoggin County, Maine | Occupied | 45393 |
| 23003 | Aroostook County, Maine | Occupied | 29784 |
| 23007 | Franklin County, Maine | Occupied | 12842 |
| 23009 | Hancock County, Maine | Occupied | 24948 |
| 23013 | Knox County, Maine | Occupied | 17883 |
| 23015 | Lincoln County, Maine | Occupied | 15803 |
| 23019 | Penobscot County, Maine | Occupied | 64250 |
| 23021 | Piscataquis County, Maine | Occupied | 7615 |
| 23025 | Somerset County, Maine | Occupied | 21924 |
| 23029 | Washington County, Maine | Occupied | 13757 |
| 23031 | York County, Maine | Occupied | 88924 |
| 23005 | Cumberland County, Maine | Occupied | 128100 |
| 23011 | Kennebec County, Maine | Occupied | 53223 |
| 23017 | Oxford County, Maine | Occupied | 24712 |
| 23023 | Sagadahoc County, Maine | Occupied | 16136 |
| 23027 | Waldo County, Maine | Occupied | 17143 |
| 23001 | Androscoggin County, Maine | Vacant | 4444 |
| 23003 | Aroostook County, Maine | Vacant | 8519 |
| 23007 | Franklin County, Maine | Vacant | 8014 |
| 23009 | Hancock County, Maine | Vacant | 15185 |
| 23013 | Knox County, Maine | Vacant | 6372 |
| 23015 | Lincoln County, Maine | Vacant | 7805 |
| 23019 | Penobscot County, Maine | Vacant | 10628 |
| 23021 | Piscataquis County, Maine | Vacant | 6962 |
| 23025 | Somerset County, Maine | Vacant | 7861 |
| 23029 | Washington County, Maine | Vacant | 7837 |
| 23031 | York County, Maine | Vacant | 23274 |
| 23005 | Cumberland County, Maine | Vacant | 21352 |
| 23011 | Kennebec County, Maine | Vacant | 9384 |
| 23017 | Oxford County, Maine | Vacant | 11418 |
| 23023 | Sagadahoc County, Maine | Vacant | 2802 |
| 23027 | Waldo County, Maine | Vacant | 4778 |
maine_unit_occupancy_2020 |>
mutate(NAME = str_remove(NAME, ", Maine")) |>
group_by(NAME) |>
select(NAME, variable, value) |>
gt() |>
cols_label(
variable = md("**Unit Status**"),
value = md("**Quantity**")) |>
tab_header(md(
"**Number of Occupied & Vacant** \\
**Units in Maine by County**"))Number of Occupied & Vacant |
|
|---|---|
Unit Status |
Quantity |
| Androscoggin County | |
| Occupied | 45393 |
| Vacant | 4444 |
| Aroostook County | |
| Occupied | 29784 |
| Vacant | 8519 |
| Franklin County | |
| Occupied | 12842 |
| Vacant | 8014 |
| Hancock County | |
| Occupied | 24948 |
| Vacant | 15185 |
| Knox County | |
| Occupied | 17883 |
| Vacant | 6372 |
| Lincoln County | |
| Occupied | 15803 |
| Vacant | 7805 |
| Penobscot County | |
| Occupied | 64250 |
| Vacant | 10628 |
| Piscataquis County | |
| Occupied | 7615 |
| Vacant | 6962 |
| Somerset County | |
| Occupied | 21924 |
| Vacant | 7861 |
| Washington County | |
| Occupied | 13757 |
| Vacant | 7837 |
| York County | |
| Occupied | 88924 |
| Vacant | 23274 |
| Cumberland County | |
| Occupied | 128100 |
| Vacant | 21352 |
| Kennebec County | |
| Occupied | 53223 |
| Vacant | 9384 |
| Oxford County | |
| Occupied | 24712 |
| Vacant | 11418 |
| Sagadahoc County | |
| Occupied | 16136 |
| Vacant | 2802 |
| Waldo County | |
| Occupied | 17143 |
| Vacant | 4778 |
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. |