Assignment 4

Author

Zachary Bechard

Occupation Table

Code
library(tidyverse)
library(gt)
library(gtExtras)
jobs <- read_csv("https://jsuleiman.com/datasets/me_grad_employment.csv")
Code
jobs <- jobs |>
  mutate(
    growth_rate = str_remove(growth_rate, "%") |> as.numeric() / 100,  
    median_wage = parse_number(median_wage),                          
    entry_wage = parse_number(entry_wage)                             
  ) |>
  arrange(desc(median_wage)) 

# Create the gt table
jobstable <- jobs |>
  select(
    occupation, base_employment, projected_employment, growth_rate, 
    annual_openings, median_wage, entry_wage
  ) |>
  gt() |>
  cols_label(
    occupation = "Occupation",
    base_employment = "Base Employment",
    projected_employment = "Projected Employment",
    growth_rate = "Growth Rate",
    annual_openings = "Annual Openings",
    median_wage = "Median Wage",
    entry_wage = "Entry Wage"
  ) |>
  tab_header(
    title = "Maine Employment Projections",
    subtitle = "Jobs That Require an Educational Degree"
  ) |>
  fmt_number(
    columns = c("base_employment", "projected_employment", "annual_openings"),
    decimals = 0,
    use_seps = TRUE
  ) |>
  fmt_percent(
    columns = c("growth_rate"),
    decimals = 2
  ) |>
  fmt_currency(
    columns = c("median_wage", "entry_wage"),
    currency = "USD",
    decimals = 2
  ) |>
  tab_style(
    style = cell_text(align = "left", weight = "normal"),
    locations = cells_body(columns = c("occupation", "growth_rate"))
  ) |>
  tab_style(
    style = cell_text(align = "right"),
    locations = cells_body(columns = c("base_employment", "projected_employment", "annual_openings", "median_wage", "entry_wage"))
  ) |>
  tab_style(
    style = cell_text(align = "left", weight = "bold"),
    locations = cells_column_labels(columns = everything())
  ) |>
  tab_style(
    style = cell_fill(color = "lightgrey"),
    locations = cells_body(
      columns = c("median_wage"),
      rows = median_wage == max(jobs$median_wage) | median_wage == min(jobs$median_wage)
    )
  ) |>
  tab_style(
    style = cell_borders(sides = "top", color = "grey", weight = px(1)),
    locations = cells_column_labels()
  ) |>
  tab_style(
    style = cell_borders(sides = "bottom", color = "grey", weight = px(1)),
    locations = cells_column_labels()
  )

jobstable
Maine Employment Projections
Jobs That Require an Educational Degree
Occupation Base Employment Projected Employment Growth Rate Annual Openings Median Wage Entry Wage
Pharmacists 1,366 1,388 2.00% 53 $135,430.00 $102,210.00
Physician Assistants 795 971 22.00% 61 $131,540.00 $109,100.00
Veterinarians 536 571 7.00% 22 $128,240.00 $90,250.00
Nurse Practitioners 1,332 1,804 35.00% 117 $123,140.00 $99,830.00
Education Administrators, Kindergarten through Secondary 1,673 1,683 1.00% 111 $98,800.00 $74,900.00
Lawyers 2,725 2,862 5.00% 121 $98,760.00 $66,090.00
Physical Therapists 1,580 1,667 6.00% 71 $90,590.00 $75,330.00
Psychologists, All Other 893 920 3.00% 60 $85,520.00 $62,970.00
Health Specialties Teachers, Postsecondary 706 797 13.00% 67 $84,500.00 $59,510.00
Biochemists and Biophysicists 414 388 −6.00% 25 $84,440.00 $67,990.00
Education Administrators, Postsecondary 752 738 −2.00% 48 $82,460.00 $60,440.00
English Language and Literature Teachers, Postsecondary 428 411 −4.00% 30 $81,960.00 $61,310.00
Business Teachers, Postsecondary 309 313 1.00% 24 $81,340.00 $56,730.00
Speech-Language Pathologists 764 852 12.00% 52 $80,210.00 $60,110.00
Occupational Therapists 1,161 1,200 3.00% 68 $79,700.00 $63,760.00
Biological Science Teachers, Postsecondary 303 311 3.00% 25 $79,220.00 $59,190.00
Art, Drama, and Music Teachers, Postsecondary 587 575 −2.00% 45 $78,380.00 $51,380.00
Nursing Instructors and Teachers, Postsecondary 404 452 12.00% 38 $77,370.00 $55,710.00
Education Teachers, Postsecondary 410 404 −1.00% 31 $76,480.00 $51,410.00
Instructional Coordinators 895 895 0.00% 76 $73,760.00 $53,990.00
Postsecondary Teachers, All Other 378 371 −2.00% 28 $72,170.00 $43,980.00
Mental Health and Substance Abuse Social Workers 1,459 1,460 0.00% 100 $66,380.00 $49,370.00
Acupuncturists 432 432 0.00% 26 $65,040.00 $44,520.00
Healthcare Social Workers 484 495 2.00% 42 $64,040.00 $54,770.00
Librarians and Media Collections Specialists 914 904 −1.00% 83 $59,010.00 $41,020.00
Educational, Guidance, and Career Counselors and Advisors 1,679 1,712 2.00% 122 $56,780.00 $42,910.00

Table Narrative

Rule 1: Offset the Headers from the Body

Implementation: To clearly distinguish the table headers from the body, I applied styling to the headers. This is achieved by using tab_style() with the cell_text(align = “left”, weight = “bold”) function, which adjusts the text alignment to left and makes it bold. This approach ensures that the headers stand out from the data, making it easier for users to navigate through the table quickly.

Rule 2: Use Subtle Dividers Instead of Heavy Gridlines

Implementation: Instead of using heavy gridlines that can clutter the visual presentation of the table, I opted for subtle dividers to separate the headers from the data rows. This was done by employing tab_style() to add minimalistic borders at the top and bottom of the column headers using cell_borders(sides = “top” and “bottom”). The choice of subtle dividers enhances the table’s readability by providing necessary separation without overwhelming the data visually.

Rule 3: Right-Align Numbers and Headers

Implementation: Numerical data and their corresponding headers were right-aligned to facilitate easy comparison across rows. This was configured using tab_style() with cell_text(align = “right”) for cells containing numerical data such as base_employment and median_wage, enhancing the table’s readability and precision.

Rule 4: Left-Align Text and Headers

Implementation: For textual data and headers, I implemented left alignment. This is particularly useful for non-numerical information, where left alignment aids in readability. Adjustments were made via tab_style(), specifying cell_text(align = “left”) for columns like occupation and growth_rate.

Rule 5: Select The Appropriate Level of Precision

Implementation: Precision in numerical presentation was carefully adjusted to balance detail with clarity. For instance, employment figures were formatted without decimals, using fmt_number() with decimals = 0. Growth rates were formatted with two decimal points to reflect more precise variations, applied through fmt_percent().

Rule 8: Highlight Outliers

Implementation: Outliers in the median_wage data were highlighted with a light grey fill (cell_fill(color = “lightgrey”)) to draw attention to these key figures. This styling was applied conditionally to the maximum and minimum values within the median_wage column, using a logical condition within tab_style().