Assignment 2

Author

Anna StPierre

Make sure to download the assign02.qmd file and a02_table.png file and put it in the folder where RStudio is looking for files. Just like in the lab, we will be using a subset from the Maine Center for Workforce Information so let’s start by loading the tidyverse family of packages, gt for making pretty tables, and read in the data. We’ll be using the message: false option to suppress the output message from loading tidyverse and gt

```{r}
#| message: false
library(tidyverse)
library(gt)
me_workforce <- read_csv("https://jsuleiman.com/datasets/maine_workforce_data.csv")
```

Exercises

There are five exercises in this assignment. The Grading Rubric is available at the end of this document.

You will recreate this chart.

This is the same data as the lab. As a reminder, here are the columns:

  • year

  • age_group

  • number - the number of people in that age group (in thousands), all numbers below are also in thousands.

  • in_labor_force - the number of people participating in the labor force (i.e., people employed + people unemployed and looking for work).

  • employed - number employed for each age group

  • unemployed - number unemployed for each age group

  • not_in_labor_force - not actively seeking employment

Exercise 1

Unemployment rate is defined as the number unemployed divided by the total number of people, we know we will need the following columns: year, age_group, unemployed, in_labor_force

Create a tibble named unemployment as subset of me_workforce that contains only the data we need.

unemployment <- me_workforce %>%
  select(year, age_group, unemployed, in_labor_force)

Exercise 2

Use the mutate function to add a column to unemployment called unemployment_rate which is unemployed / in_labor_force.

unemployment <- unemployment %>%
  mutate(unemployment_rate = unemployed / in_labor_force)

Exercise 3

Before we pivot_wider to create our table, we want to eliminate any data we don’t need for our chart. Now that we calculated unemployment_rate create a new tibble called unemployment_chart that contains year, age_group, and unemployment_rate from unemployment.

unemployment_chart <- unemployment %>%
  select(year, age_group, unemployment_rate)

Exercise 4

Now we can use pivot_wider to make the tibble contain similar data to our chart. See the hints from Lab 2 if you need a refresher. Make sure you filter so the tibble only contains the last five years of data (2019 - 2023)

unemployment_wide <- unemployment_chart %>%
  filter(year %in% 2019:2023) %>%
  pivot_wider(names_from = year, values_from = unemployment_rate)

### Exercise 5
unemployment_wide %>%
  gt() %>%
  fmt_percent(
    columns = c("2019", "2020", "2021", "2022", "2023"),
    decimals = 1
  ) %>%
  tab_caption(
    caption = "Unemployment Rate by Age Group (2019–2023)"
  ) %>%
  fmt_missing(
    columns = everything(),
    missing_text = ""
  )
Warning: Since gt v0.6.0 `fmt_missing()` is deprecated and will soon be removed.
ℹ Use `sub_missing()` instead.
This warning is displayed once every 8 hours.
Unemployment Rate by Age Group (2019–2023)
age_group 2023 2022 2021 2020 2019
16-24
9.9%

7.1%
25-34 2.9% 3.1% 5.3% 5.4% 3.0%
35-44 2.0% 2.6% 4.8% 3.8% 2.3%
45-54 2.5% 2.4% 2.5% 5.6% 1.5%
55-64 1.5% 1.6% 5.0% 3.4% 2.1%
65+ 3.3% 4.8% 3.2% 6.6% 5.9%

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
Narrative: typos and grammatical errors
(8%)
Document formatting: correctly implemented instructions
(8%)

Exercises

(15% each)

Submitted properly to Brightspace

(9%)

NA NA You must submit according to instructions to receive any credit for this portion.