Assignment 2

Author

Grace-Ann Walker

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.

# insert Exercise 1 code here.
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.

# insert Exercise 2 code here.
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.

# insert Exercise 3 code here.
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)

# insert Exercise 4 code here.
unemployment_chart <- unemployment_chart |>
  pivot_wider(names_from = age_group, values_from = unemployment_rate) |>
  filter(year >= 2019)
glimpse(unemployment_chart)
Rows: 5
Columns: 7
$ year    <dbl> 2023, 2022, 2021, 2020, 2019
$ `16-24` <dbl> NA, 0.09876543, NA, NA, 0.07142857
$ `25-34` <dbl> 0.02877698, 0.03100775, 0.05343511, 0.05384615, 0.03030303
$ `35-44` <dbl> 0.01973684, 0.02649007, 0.04827586, 0.03759398, 0.02343750
$ `45-54` <dbl> 0.02521008, 0.02419355, 0.02500000, 0.05645161, 0.01492537
$ `55-64` <dbl> 0.01470588, 0.01600000, 0.05000000, 0.03401361, 0.02054795
$ `65+`   <dbl> 0.03278689, 0.04761905, 0.03225806, 0.06557377, 0.05882353

Exercise 5

Replicate the table. Remember to format percentages, include a caption, and don’t display NA values. See Lab 2 for hints.

# insert Exercise 5 code here.
unemployment_chart |> 
  gt(caption = "ME Unemployment Rate by Age Group") |> 
  fmt_percent(columns = c("16-24", "25-34", "35-44", "45-54", "55-64", "65+"), 
              decimals = 1) |> 
  sub_missing(missing_text = "")
ME Unemployment Rate by Age Group
year 16-24 25-34 35-44 45-54 55-64 65+
2023
2.9% 2.0% 2.5% 1.5% 3.3%
2022 9.9% 3.1% 2.6% 2.4% 1.6% 4.8%
2021
5.3% 4.8% 2.5% 5.0% 3.2%
2020
5.4% 3.8% 5.6% 3.4% 6.6%
2019 7.1% 3.0% 2.3% 1.5% 2.1% 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.