library(tidyverse) #I do not know why I see this message, I only see it in R Markdown
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(ggrepel)
library(readxl)

astronaut <- read_excel("/Users/dylansimon/Documents/Personal/UF Classes/Microbial Data Analysis (R)/astronaut.xlsx")
#path to dataset on my local device

theme_set(theme_bw())

plotting_data <- astronaut %>%
  mutate(Expression = dplyr::case_when(Fold_change > 1 & pvalue < 0.05 ~ "up-regulated",
                                       Fold_change < -1 & pvalue < 0.05 ~ "down-regulated",
                                       TRUE ~ "not significant"))

regulated_genes <- plotting_data %>%
  filter(Expression == "up-regulated" | Expression == "down-regulated")

plot <- ggplot(plotting_data, aes(x = Fold_change, y = -log(pvalue, 10))) +
                 geom_point(aes(color = Expression)) +
                 xlab(expression("Fold Change")) + #text formatted to add subscript 2
                 ylab(expression("-log"[10]*"(p-value)")) +
                 scale_color_manual(values = c("firebrick3","grey50", "green3"))

plot <- plot +
  geom_label_repel(data = regulated_genes, label = regulated_genes$Feature.ID, label.size = NA, fill= NA)


plot