library(tidyverse)
## ── 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   4.0.0     ✔ tibble    3.3.0
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.1.0     
## ── 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
myconditions <- read.csv("conditions_annotation.csv")
myexpression <- read.csv("SC_expression.csv")
myfilter <- myconditions[grepl("itc1",myconditions$primary),] 
myexpression2 <-
  myexpression%>%
  select(myfilter$ID)
tidyExpression <- myexpression2 %>% pivot_longer(cols = everything())
by_treatment <- tidyExpression %>%
  group_by(name)

by_treatment  %>%
  summarise_all(list(mean = mean, median  = median, n=length))
## # A tibble: 2 × 4
##   name    mean median     n
##   <chr>  <dbl>  <dbl> <int>
## 1 AFIINC  165.   3.62  6071
## 2 AFNAQI  165.   3.97  6071
library(ggplot2)

ggplot(tidyExpression, aes(x = name, y = log(value))) + 
  geom_violin(fill = "lightblue", color = "black", alpha = 0.6) +  # violin styling
  geom_jitter(width = 0.15, alpha = 0.5, size = 1.2, color = "darkblue") +  # add raw points
  stat_summary(fun = "mean", geom = "point", shape = 18, size = 3, color = "red") +  # mean point
  stat_summary(fun.data = mean_cl_normal, geom = "errorbar", width = 0.2, color = "red") +  # CI bars
  theme_minimal(base_size = 14) +  # clean theme
  labs(x = "Gene", y = "Log(Expression Value)", 
       title = "Violin Plot of Gene Expression with Stats")  # axis labels + title
## Warning: Removed 329 rows containing non-finite outside the scale range
## (`stat_ydensity()`).
## Warning: Removed 329 rows containing non-finite outside the scale range
## (`stat_summary()`).
## Removed 329 rows containing non-finite outside the scale range
## (`stat_summary()`).