# intro_R_workshop_20260724.R
#
# This script file contains the code I wrote during MI-Support's Intro to R
#   workshop hosted by the Ingham County Health Department on
#   Friday, July 24, 2026.
# For help on this stuff later, I can use MI-Support's R Office Hours link:
#   https://calendly.com/jackjacobs-misupport/30min
#
# Author: Marisa Eisenberg 

install.packages(c("tidyverse","this.path","janitor"))

library(tidyverse)
library(this.path)

hello <- 7
hello = 7

this.dir()

here("FAKE_pertussis_mdss.csv")


mdss <- read_csv(here("FAKE_pertussis_mdss.csv"), skip = 1)


mdss = mdss |>
  
  # Select - grab the columns we want
  select(InvestigationID, Onset_Date, Diagnosis_Date, Referral_Date, 
         Patient_Status, Case_Disposition, Date_of_Birth, Date_of_Death,
         Sex, Age, Admission_Date) |>
  
  # Janitor is a helpful cleanup package
  janitor::clean_names()


# Quick preview
mdss |> 
  ggplot(aes(x = year(mdy(diagnosis_date)), fill = sex)) +
  geom_col(stat = "count", position = "dodge")


pop = read_csv(here("population.csv"))


mdss = mdss |>
  
  # Mutate: when you want to make new or nicer variables!
  mutate(diagnosis_year = year(mdy( diagnosis_date ) ) )  |>
  
  filter(diagnosis_year >= 2019) |>
  
  rename(age_years = age)


# Summary!

summary = mdss |>
  group_by(diagnosis_year, sex) |>
  summarize(cases = n(), .groups = "drop")

summary |>
  ggplot(aes(x = diagnosis_year, y = cases, fill = sex)) + 
  geom_col(position = "dodge") + 
  scale_fill_manual("Sex", values = c("Female" = "#73A950", "Male" = "#00629B")) + 
  theme_classic() + 
  labs(title = "Pertussis Cases by Year", x = "Year", y = "Cases")


pop |>
  ggplot(aes(x = year, y = population, fill = sex)) + 
  geom_col(position = "dodge") + 
  scale_fill_manual("Sex", values = c("Female" = "#73A950", "Male" = "#00629B")) + 
  theme_classic() + 
  labs(title = "Population by Year", x = "Year", y = "Population")
  
  
  
  
  
  
  




