Q1: Prepare data for joined such as calculate any remaining data elements needed for analysis

# modify the vaccination df
vax_join <- filter(ca_vax_select, demographic_category=="Gender")
vax_join <- filter(vax_join, !demographic_value=="Unknown/undifferentiated")
vax_join <- rename(vax_join, "sex"="demographic_value")
vax_join <- vax_join %>%
  select(c(-demographic_category,-county_type))

vax_join$sex <- tolower(vax_join$sex)

# create vaccination df for joining
vax_join2 <- vax_join %>%
  group_by(county_name, sex) %>%
  summarize(cumulative_fully_vaccinated = max(cumulative_fully_vaccinated), max(total_partial_vaccinated), cumulative_unvaccinated = max(cumulative_unvaccinated)) %>%
  ungroup()

# modify the flu df
flu_merged_date$sex <- tolower(flu_merged_date$sex)

flu_merged_date$county <- gsub(" County", "", flu_merged_date$county)

flu_merged_date <- flu_merged_date %>%
  mutate(cumulative_incidence = new_infections/count_susceptible)

# create flu df for joining
flu_join2 <- flu_merged_date %>%
  group_by(county, sex) %>%
  summarize(tot_new_infections = sum(new_infections), cumulative_severe = max(cumulative_severe), cumulative_infected = max(cumulative_infected), count_susceptible = max(count_susceptible)) %>%
  ungroup()

# join the data frames
joined <- full_join(vax_join2, flu_join2, by=c("county_name"="county", "sex"="sex"))

# remove Statewide
joined <- joined[-c(101, 102), ]

Q2: Visualizations: 1 per group member

Plot #1

# Cumulative covid vaccination rates vs flu infections

library(plotly)

# Table of top 10 counties with most new infections, stratified by gender
joined_top <- joined %>%
  group_by(county_name) %>%
  filter(tot_new_infections>220000) %>%
  ungroup()

#remove sex columns and sum vaccine and influenza cases based on county name 
joined_remove_sex <- joined_top %>% 
  select(-sex) %>% 
  group_by(county_name) %>%
  summarise_all(sum) %>%
  ungroup()

#graphing flu infections vs covid vaccinations
plot1 <- joined_remove_sex %>% plot_ly(
  x = ~county_name, 
  y = ~tot_new_infections,  
  name = "Total Flu infections",
  type = "bar", 
  mode = "bar")%>%
  add_trace(y = ~count_susceptible, name = "Total No Flu infections", colors="darkorange")%>%
  layout(
    title="Cumulative Flu Cases with COVID Unvaccination in Ca Counties",
    yaxis=list(title="Count", range = c(0,11,000)),
    xaxis=list(title="Ca Counties"),
    paper_bgcolor="azure",
    plot_bgcolor="white", 
    legend = list(x = 0.7, y = 0.9)) 

plot2 <- joined_remove_sex %>% plot_ly(
  x = ~county_name, 
  y = ~cumulative_fully_vaccinated,  
  name = "Indv who are fully vaccinated",
  type = "bar", 
  mode = "bar")%>%
  add_trace(y = ~cumulative_unvaccinated, name = "Indv who have not received COVID Vaccines", colors="darkorange")%>%
  layout(
    title="COVID-19 Vaccinations & Flu Cases in 10 CA Counties from 2022-2023",
    yaxis=list(title="Count", range = c(0,11,000)),
    xaxis=list(title="Ca Counties"),
    paper_bgcolor="azure",
    plot_bgcolor="white", 
    barmode = 'group', 
    legend = list(x = 0.7, y = 0.9)) 

final_bar <- subplot(plot1, plot2, nrows = 1)

final_bar

Interpretation: The graph on the left displays the total flu infections comparing the total new infections to the total amount of no new infections for each of the 10 CA counties. The graph on the right displays the total COVID-19 vaccinations comparing fully vaccinated status to non-vaccinated for each of the 10 CA counties.

Table

# data frame to be used in kable
joined_kable <- joined[, c("county_name", "sex", "tot_new_infections")]

joined_pivot <- joined_kable %>% pivot_wider(
  names_from = sex, 
  values_from = tot_new_infections
)

# Creating table
kable(joined_pivot,
      booktabs = T,
      col.names = c("County Name", "Female", "Male"), 
      caption = "Flu Cases in each County by Sex from January 2022 - July 2023") %>%
 kable_styling(full_width=F) %>%
  column_spec(1, bold=TRUE) %>%
  row_spec(0, extra_css="border-bottom: 2px solid #000") %>%
  column_spec(2, color=if_else(joined_pivot$female > 220000, "red","black","black")) %>%
  column_spec(3, color=if_else(joined_pivot$male > 220000, "red","black","black")) %>%
  footnote(general = "Top 10 Counties with highest Flu Cases highlighted")
Flu Cases in each County by Sex from January 2022 - July 2023
County Name Female Male
Alameda 370269 360524
Alpine 245 251
Amador 7462 8858
Butte 49237 49380
Calaveras 9545 9488
Colusa 4838 5060
Contra Costa 256883 247977
Del Norte 5302 6347
El Dorado 40626 41476
Fresno 221665 223271
Glenn 6207 6465
Humboldt 29212 29166
Imperial 41167 42457
Inyo 3884 4009
Kern 195668 206219
Kings 30365 36913
Lake 13812 13980
Lassen 4801 7921
Los Angeles 2021291 1967189
Madera 36080 34263
Marin 56239 55063
Mariposa 3734 3827
Mendocino 19220 19099
Merced 61740 63258
Modoc 2026 2072
Mono 2809 3125
Monterey 93732 99846
Napa 30129 30304
Nevada 21280 21034
Orange 698013 693714
Placer 88211 85542
Plumas 4041 4093
Riverside 544013 539737
Sacramento 344104 335159
San Benito 13436 13496
San Bernardino 480389 477833
San Diego 718939 732021
San Francisco 192114 196860
San Joaquin 168702 169348
San Luis Obispo 58687 62052
San Mateo 169548 166276
Santa Barbara 97522 99742
Santa Clara 423544 434603
Santa Cruz 59528 60129
Shasta 38740 37526
Sierra 654 642
Siskiyou 9493 9270
Solano 97171 96578
Sonoma 110202 107177
Stanislaus 122758 121886
Sutter 21941 21631
Tehama 13769 13776
Trinity 2836 2888
Tulare 104307 105403
Tuolumne 10658 11741
Ventura 184123 183206
Yolo 50891 47897
Yuba 17077 17239
Note:
Top 10 Counties with highest Flu Cases highlighted

Interpretation: The above table displays the total new flu infections of all counties in the state of California stratified by sex, with red text for the top 10 counties.

Plot #2

# Graph of top 10 counties with most new infections, stratified by gender
ggplot(data=joined_top, aes(x=county_name, y=tot_new_infections, fill=sex)) +
  geom_bar(stat="identity", position=position_dodge()) +
  labs(x = "County Name", y = "Total New Infections", fill="Sex",
                  title = "Total New Flu Infections by Sex", subtitle = "Top 10 CA Counties with Highest New Infections from from January 2022 - July 2023") +
  theme(axis.text.x = element_text(size = 11, angle = 60, hjust = 1, vjust = 0.9)) +
  scale_fill_manual(name="Sex", labels = c("Female", "Male"), values=c("pink","lightblue")) 

Interpretation: The cumulative total new flu infections is similar amongst sex but varies slightly by county of the top 10 counties with the highest values. Los Angeles county has over 100% more cumulative flu cases than the next highest county, which is San Diego.