1. Install packages and load libraries

#install.packages("tidyverse")
#install.packages("ggplot2")
library(tidyverse)
library(readxl)
library(ggplot2)

2. Read in our data

#read in Johanna's excel sheet
df <- read_csv("R01 data by subject_summary.csv", show_col_types = FALSE)

Manipulate the data

#if you want to convert to numeric, but they are already doubles so you technically don't need to, but here is a quick way to do it
df <- df %>%
  mutate(across(c(IgE_0, IgG4_0, OFC_0, SPT_0), as.numeric))

#make a long version
df_long <- gather(df, variable, value, IgG4_0, SPT_0, OFC_0, Outcome)

3. Plot data

#save custom ggplot aesthetics that I will use in the next code chunk
gghisto <- list(
  theme(axis.text.x = element_text(face="bold", size=10, color = "Navyblue"),
          axis.text.y = element_text(face="bold", 
          size=6),
          axis.title=element_text(size=17),
          plot.title = element_text(size=17,face="bold")))
#Create the scatter plot with color mapping using the facet_wrap() function

color_palette <- c("magenta","purple","lightblue","darkslateblue")


ggplot(df_long, aes(x = IgE_0, y = value, fill = variable)) +
  geom_point(size = 4, shape = 21, alpha = 0.7) +
  facet_wrap(~ variable, scales = "free", ncol = 2) +
  labs(title = "Scatter Plots of IgE_0 vs. Other Features",
       x = "IgE_0") +
  scale_fill_manual(values = color_palette) +
  theme(strip.text = element_text(face = "bold")) +
  gghisto