Assignment 4

Author

Brady Heath

Code
library(tidyverse)
library(gt)
Warning: package 'gt' was built under R version 4.4.3
Code
library(gtExtras)
Warning: package 'gtExtras' was built under R version 4.4.3
Code
jobs <- read_csv("https://jsuleiman.com/datasets/me_grad_employment.csv")
Code
colnames(jobs) 
[1] "occupation"           "base_employment"      "projected_employment"
[4] "growth_rate"          "annual_openings"      "wage_year"           
[7] "median_wage"          "entry_wage"          

Table Rules:

  1. Offset the headers from the body
  2. Use subtle dividers instead of heavy gridlines
  3. right-align numbers and headers
  4. left-align text and header
  5. select the appropriate level of precision
  1. Highlight Outliers

Table

Code
gt_table <- jobs |>
  gt() |>
  fmt_number(
    columns = c(occupation, base_employment, projected_employment, growth_rate, annual_openings, wage_year, median_wage, entry_wage),
    decimals = 2,
    use_seps = TRUE,
    accounting = TRUE,
  ) |>
  fmt_number(
    columns = wage_year,
    decimals = 0,
    use_seps = FALSE
  ) |>
   tab_options(
    table.border.top.width = px(1),
    table.border.top.color = "gray",
    table.border.bottom.width = px(1),
    table.border.bottom.color = "gray",
    heading.border.bottom.color = "gray",
    row.striping.background_color = "gray",  
    column_labels.border.bottom.color = "gray",
    column_labels.border.top.color = "gray",
    data_row.padding = px(6)
  ) |>
  opt_table_lines()

gt_table
occupation base_employment projected_employment growth_rate annual_openings wage_year median_wage entry_wage
Lawyers 2,725.00 2,862.00 5% 121.00 2023 $98760 $66090
Educational, Guidance, and Career Counselors and Advisors 1,679.00 1,712.00 2% 122.00 2023 $56780 $42910
Education Administrators, Kindergarten through Secondary 1,673.00 1,683.00 1% 111.00 2023 $98800 $74900
Physical Therapists 1,580.00 1,667.00 6% 71.00 2023 $90590 $75330
Mental Health and Substance Abuse Social Workers 1,459.00 1,460.00 0% 100.00 2023 $66380 $49370
Pharmacists 1,366.00 1,388.00 2% 53.00 2023 $135430 $102210
Nurse Practitioners 1,332.00 1,804.00 35% 117.00 2023 $123140 $99830
Occupational Therapists 1,161.00 1,200.00 3% 68.00 2023 $79700 $63760
Librarians and Media Collections Specialists 914.00 904.00 -1% 83.00 2023 $59010 $41020
Instructional Coordinators 895.00 895.00 0% 76.00 2023 $73760 $53990
Psychologists, All Other 893.00 920.00 3% 60.00 2023 $85520 $62970
Physician Assistants 795.00 971.00 22% 61.00 2023 $131540 $109100
Speech-Language Pathologists 764.00 852.00 12% 52.00 2023 $80210 $60110
Education Administrators, Postsecondary 752.00 738.00 -2% 48.00 2023 $82460 $60440
Health Specialties Teachers, Postsecondary 706.00 797.00 13% 67.00 2023 $84500 $59510
Art, Drama, and Music Teachers, Postsecondary 587.00 575.00 -2% 45.00 2023 $78380 $51380
Veterinarians 536.00 571.00 7% 22.00 2023 $128240 $90250
Healthcare Social Workers 484.00 495.00 2% 42.00 2023 $64040 $54770
Acupuncturists 432.00 432.00 0% 26.00 2023 $65040 $44520
English Language and Literature Teachers, Postsecondary 428.00 411.00 -4% 30.00 2023 $81960 $61310
Biochemists and Biophysicists 414.00 388.00 -6% 25.00 2023 $84440 $67990
Education Teachers, Postsecondary 410.00 404.00 -1% 31.00 2023 $76480 $51410
Nursing Instructors and Teachers, Postsecondary 404.00 452.00 12% 38.00 2023 $77370 $55710
Postsecondary Teachers, All Other 378.00 371.00 -2% 28.00 2023 $72170 $43980
Business Teachers, Postsecondary 309.00 313.00 1% 24.00 2023 $81340 $56730
Biological Science Teachers, Postsecondary 303.00 311.00 3% 25.00 2023 $79220 $59190

Change header and align tabs to left

Code
gt_table <- gt_table |>
  tab_header (
    title = "Maine Jobs Requiring a Professional Degree"
  ) |>
  tab_options(
    heading.align = "left"
  ) |>
  tab_style(
    style = cell_text(weight = "bolder"),
    locations = cells_title(groups = "title")
  )
  gt_table
Maine Jobs Requiring a Professional Degree
occupation base_employment projected_employment growth_rate annual_openings wage_year median_wage entry_wage
Lawyers 2,725.00 2,862.00 5% 121.00 2023 $98760 $66090
Educational, Guidance, and Career Counselors and Advisors 1,679.00 1,712.00 2% 122.00 2023 $56780 $42910
Education Administrators, Kindergarten through Secondary 1,673.00 1,683.00 1% 111.00 2023 $98800 $74900
Physical Therapists 1,580.00 1,667.00 6% 71.00 2023 $90590 $75330
Mental Health and Substance Abuse Social Workers 1,459.00 1,460.00 0% 100.00 2023 $66380 $49370
Pharmacists 1,366.00 1,388.00 2% 53.00 2023 $135430 $102210
Nurse Practitioners 1,332.00 1,804.00 35% 117.00 2023 $123140 $99830
Occupational Therapists 1,161.00 1,200.00 3% 68.00 2023 $79700 $63760
Librarians and Media Collections Specialists 914.00 904.00 -1% 83.00 2023 $59010 $41020
Instructional Coordinators 895.00 895.00 0% 76.00 2023 $73760 $53990
Psychologists, All Other 893.00 920.00 3% 60.00 2023 $85520 $62970
Physician Assistants 795.00 971.00 22% 61.00 2023 $131540 $109100
Speech-Language Pathologists 764.00 852.00 12% 52.00 2023 $80210 $60110
Education Administrators, Postsecondary 752.00 738.00 -2% 48.00 2023 $82460 $60440
Health Specialties Teachers, Postsecondary 706.00 797.00 13% 67.00 2023 $84500 $59510
Art, Drama, and Music Teachers, Postsecondary 587.00 575.00 -2% 45.00 2023 $78380 $51380
Veterinarians 536.00 571.00 7% 22.00 2023 $128240 $90250
Healthcare Social Workers 484.00 495.00 2% 42.00 2023 $64040 $54770
Acupuncturists 432.00 432.00 0% 26.00 2023 $65040 $44520
English Language and Literature Teachers, Postsecondary 428.00 411.00 -4% 30.00 2023 $81960 $61310
Biochemists and Biophysicists 414.00 388.00 -6% 25.00 2023 $84440 $67990
Education Teachers, Postsecondary 410.00 404.00 -1% 31.00 2023 $76480 $51410
Nursing Instructors and Teachers, Postsecondary 404.00 452.00 12% 38.00 2023 $77370 $55710
Postsecondary Teachers, All Other 378.00 371.00 -2% 28.00 2023 $72170 $43980
Business Teachers, Postsecondary 309.00 313.00 1% 24.00 2023 $81340 $56730
Biological Science Teachers, Postsecondary 303.00 311.00 3% 25.00 2023 $79220 $59190
Code
gt_table <- gt_table |>
  cols_label(
    occupation = "Occupation",
    base_employment = "Current Employment",
    projected_employment = "Future Employment",
    growth_rate = "Growth",
    annual_openings = "Openings",
    wage_year = "Year",
    median_wage = "Average Wage",
    entry_wage = "Starting Wage"
  ) |>
  tab_style(
    style = cell_text(weight = "bold"),
    locations = cells_column_labels(everything())
  )
gt_table
Maine Jobs Requiring a Professional Degree
Occupation Current Employment Future Employment Growth Openings Year Average Wage Starting Wage
Lawyers 2,725.00 2,862.00 5% 121.00 2023 $98760 $66090
Educational, Guidance, and Career Counselors and Advisors 1,679.00 1,712.00 2% 122.00 2023 $56780 $42910
Education Administrators, Kindergarten through Secondary 1,673.00 1,683.00 1% 111.00 2023 $98800 $74900
Physical Therapists 1,580.00 1,667.00 6% 71.00 2023 $90590 $75330
Mental Health and Substance Abuse Social Workers 1,459.00 1,460.00 0% 100.00 2023 $66380 $49370
Pharmacists 1,366.00 1,388.00 2% 53.00 2023 $135430 $102210
Nurse Practitioners 1,332.00 1,804.00 35% 117.00 2023 $123140 $99830
Occupational Therapists 1,161.00 1,200.00 3% 68.00 2023 $79700 $63760
Librarians and Media Collections Specialists 914.00 904.00 -1% 83.00 2023 $59010 $41020
Instructional Coordinators 895.00 895.00 0% 76.00 2023 $73760 $53990
Psychologists, All Other 893.00 920.00 3% 60.00 2023 $85520 $62970
Physician Assistants 795.00 971.00 22% 61.00 2023 $131540 $109100
Speech-Language Pathologists 764.00 852.00 12% 52.00 2023 $80210 $60110
Education Administrators, Postsecondary 752.00 738.00 -2% 48.00 2023 $82460 $60440
Health Specialties Teachers, Postsecondary 706.00 797.00 13% 67.00 2023 $84500 $59510
Art, Drama, and Music Teachers, Postsecondary 587.00 575.00 -2% 45.00 2023 $78380 $51380
Veterinarians 536.00 571.00 7% 22.00 2023 $128240 $90250
Healthcare Social Workers 484.00 495.00 2% 42.00 2023 $64040 $54770
Acupuncturists 432.00 432.00 0% 26.00 2023 $65040 $44520
English Language and Literature Teachers, Postsecondary 428.00 411.00 -4% 30.00 2023 $81960 $61310
Biochemists and Biophysicists 414.00 388.00 -6% 25.00 2023 $84440 $67990
Education Teachers, Postsecondary 410.00 404.00 -1% 31.00 2023 $76480 $51410
Nursing Instructors and Teachers, Postsecondary 404.00 452.00 12% 38.00 2023 $77370 $55710
Postsecondary Teachers, All Other 378.00 371.00 -2% 28.00 2023 $72170 $43980
Business Teachers, Postsecondary 309.00 313.00 1% 24.00 2023 $81340 $56730
Biological Science Teachers, Postsecondary 303.00 311.00 3% 25.00 2023 $79220 $59190

Highlight negative values (outliers)

Code
library(gt)
gt_table |> 
  tab_style(
    style = cell_text(color = "red", weight = "bold"), 
    locations = cells_body(
      columns = growth_rate, 
      rows = growth_rate < 0 
    )
  )
Maine Jobs Requiring a Professional Degree
Occupation Current Employment Future Employment Growth Openings Year Average Wage Starting Wage
Lawyers 2,725.00 2,862.00 5% 121.00 2023 $98760 $66090
Educational, Guidance, and Career Counselors and Advisors 1,679.00 1,712.00 2% 122.00 2023 $56780 $42910
Education Administrators, Kindergarten through Secondary 1,673.00 1,683.00 1% 111.00 2023 $98800 $74900
Physical Therapists 1,580.00 1,667.00 6% 71.00 2023 $90590 $75330
Mental Health and Substance Abuse Social Workers 1,459.00 1,460.00 0% 100.00 2023 $66380 $49370
Pharmacists 1,366.00 1,388.00 2% 53.00 2023 $135430 $102210
Nurse Practitioners 1,332.00 1,804.00 35% 117.00 2023 $123140 $99830
Occupational Therapists 1,161.00 1,200.00 3% 68.00 2023 $79700 $63760
Librarians and Media Collections Specialists 914.00 904.00 -1% 83.00 2023 $59010 $41020
Instructional Coordinators 895.00 895.00 0% 76.00 2023 $73760 $53990
Psychologists, All Other 893.00 920.00 3% 60.00 2023 $85520 $62970
Physician Assistants 795.00 971.00 22% 61.00 2023 $131540 $109100
Speech-Language Pathologists 764.00 852.00 12% 52.00 2023 $80210 $60110
Education Administrators, Postsecondary 752.00 738.00 -2% 48.00 2023 $82460 $60440
Health Specialties Teachers, Postsecondary 706.00 797.00 13% 67.00 2023 $84500 $59510
Art, Drama, and Music Teachers, Postsecondary 587.00 575.00 -2% 45.00 2023 $78380 $51380
Veterinarians 536.00 571.00 7% 22.00 2023 $128240 $90250
Healthcare Social Workers 484.00 495.00 2% 42.00 2023 $64040 $54770
Acupuncturists 432.00 432.00 0% 26.00 2023 $65040 $44520
English Language and Literature Teachers, Postsecondary 428.00 411.00 -4% 30.00 2023 $81960 $61310
Biochemists and Biophysicists 414.00 388.00 -6% 25.00 2023 $84440 $67990
Education Teachers, Postsecondary 410.00 404.00 -1% 31.00 2023 $76480 $51410
Nursing Instructors and Teachers, Postsecondary 404.00 452.00 12% 38.00 2023 $77370 $55710
Postsecondary Teachers, All Other 378.00 371.00 -2% 28.00 2023 $72170 $43980
Business Teachers, Postsecondary 309.00 313.00 1% 24.00 2023 $81340 $56730
Biological Science Teachers, Postsecondary 303.00 311.00 3% 25.00 2023 $79220 $59190

How each rule was implemented:

  1. Offset the headers from the body

    to offset the headers from the body I made my title and column labels bold to visually separate them.

  2. Use subtle dividers instead of heavy grid lines

    To create a more organized look and reduce visual clutter I implemented subtle dividers if the dividers are too bold they can seem more distracting then a lighter divier which creates the subtle visual separation.

  3. right-align numbers and headers

    Setting the accounting value to true makes all numbers align-right.

  4. left-align text and header

    using heading.align = left under tab options sets my headers and title to be aligned left.

  5. select the appropriate level of precision

Setting decimals to 2 sets the decimal place to show up to the hundredths place which can show important variations.

  1. Highlight Outliers
**To highlight the outliers in my table i highlighted the negative numbers under the growth rate column.**

Generative AI Citation