library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.2
library(ggpubr)
library(ggbeeswarm)
## Warning: package 'ggbeeswarm' was built under R version 4.3.3
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(readxl)
## Warning: package 'readxl' was built under R version 4.3.2
library(fmsb)
## Warning: package 'fmsb' was built under R version 4.3.3
windowsFonts(Arial = windowsFont("Arial"))
# Defines a colorblind-friendly palette
cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
COMBINED<- read_excel("Z:/TSinozic/Histo/2024_12 December - CHIL3/Copy of Analysis_CHIL3_MPO_1.xlsx", 
    sheet = "combined")

kc<- read_excel("Z:/TSinozic/Histo/2024_12 December - CHIL3/Copy of Analysis_CHIL3_MPO_1.xlsx", 
    sheet = "kid_CHIL3")
lc<- read_excel("Z:/TSinozic/Histo/2024_12 December - CHIL3/Copy of Analysis_CHIL3_MPO_1.xlsx", 
    sheet = "liv_CHIL3")
sc<- read_excel("Z:/TSinozic/Histo/2024_12 December - CHIL3/Copy of Analysis_CHIL3_MPO_1.xlsx", 
    sheet = "spl_CHIL3")

lm<- read_excel("Z:/TSinozic/Histo/2024_12 December - CHIL3/Copy of Analysis_CHIL3_MPO_1.xlsx", 
    sheet = "liv_MPO")
sm<- read_excel("Z:/TSinozic/Histo/2024_12 December - CHIL3/Copy of Analysis_CHIL3_MPO_1.xlsx", 
    sheet = "spl_MPO")
tilen<- read_excel("Z:/TSinozic/Histo/2024_12 December - CHIL3/Copy of Analysis_CHIL3_MPO_1.xlsx", 
    sheet = "tilen")

KIDNEY CHIL3

# Orders the variables on x-axis
kc$variable <- factor(kc$variable, levels = c("WT", "KO"))
# Calculates averages of each replicate
ReplicateAverages <- kc %>% group_by(variable, replicate) %>%
  summarise_each(list(mean))
## Warning: `summarise_each_()` was deprecated in dplyr 0.7.0.
## ℹ Please use `across()` instead.
## ℹ The deprecated feature was likely used in the dplyr package.
##   Please report the issue at <https://github.com/tidyverse/dplyr/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
ReplicateAverages
## # A tibble: 6 × 3
## # Groups:   variable [2]
##   variable replicate   value
##   <fct>        <dbl>   <dbl>
## 1 WT               1 0.00951
## 2 WT               2 0.0361 
## 3 WT               3 0.00993
## 4 KO               1 0.299  
## 5 KO               2 0.123  
## 6 KO               3 0.0624
# Gives the p-value for the t-Test of variable 1 and 2
ttest1 <- t.test(x=ReplicateAverages$value[1:3], y=ReplicateAverages$value[4:6],paired = FALSE, alternative="two.sided",var.equal = FALSE)
ttest1p <- ttest1[["p.value"]]
ttest1p
## [1] 0.1792585
# Calculates total averages
TotalAverages <- ReplicateAverages %>% summarise_each(list(mean))
TotalAverages
## # A tibble: 2 × 3
##   variable replicate  value
##   <fct>        <dbl>  <dbl>
## 1 WT               2 0.0185
## 2 KO               2 0.162
# Plots Superplot based on biological replicate averages
kc<-ggplot(kc, aes(x=variable,y=value,color=factor(replicate))) +

  # Adds individual data points
  geom_beeswarm(cex=3) +
  
  # Adds mean values as bars
  stat_summary(data = TotalAverages, fun = mean, fun.min = mean, fun.max = mean,
               geom = "crossbar", width = 0.25, color = "black") +
               
  # Adds error bars
  stat_summary(data = ReplicateAverages, fun.data = mean_se,
               geom = "errorbar", width = 0.1, color = "black", size= 1) +
               
  # Adds color palette
  scale_colour_manual(values=cbPalette) +
  
  # Adds Replicative averages as points (argument "cex" can be used to spread the data points if the averages are close together)
  geom_beeswarm(data=ReplicateAverages, size=5) +
  
  #Cosmetics and labeling
  theme_bw() + theme(axis.line = element_line(size = 1, colour = "black"),
                     legend.position = "none",
                     axis.title.y = element_text(family="Arial", size=28, color = "black", vjust = 2),
                     axis.text = element_text(family="Arial", size = 28, color = "black"),
                     axis.ticks = element_line(size = 1, color = "black"), 
                     axis.ticks.length = unit(2, "mm"),
                     panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(),
                     panel.background = element_blank(), 
                     panel.border = element_blank()) +
  xlab("") + ylab("Total counts")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
kc

LIVER CHIL3

# Orders the variables on x-axis
lc$variable <- factor(lc$variable, levels = c("WT", "KO"))
# Calculates averages of each replicate
ReplicateAverages <- lc %>% group_by(variable, replicate) %>%
  summarise_each(list(mean))
ReplicateAverages
## # A tibble: 6 × 3
## # Groups:   variable [2]
##   variable replicate     value
##   <fct>        <dbl>     <dbl>
## 1 WT               1 0.000407 
## 2 WT               2 0.0000904
## 3 WT               3 0.000119 
## 4 KO               1 0.00191  
## 5 KO               2 0.00267  
## 6 KO               3 0.0633
# Gives the p-value for the t-Test of variable 1 and 2
ttest1 <- t.test(x=ReplicateAverages$value[1:3], y=ReplicateAverages$value[4:6],paired = FALSE, alternative="two.sided",var.equal = FALSE)
ttest1p <- ttest1[["p.value"]]
ttest1p
## [1] 0.3851644
# Calculates total averages
TotalAverages <- ReplicateAverages %>% summarise_each(list(mean))
TotalAverages
## # A tibble: 2 × 3
##   variable replicate    value
##   <fct>        <dbl>    <dbl>
## 1 WT               2 0.000205
## 2 KO               2 0.0226
# Plots Superplot based on biological replicate averages
lc<-ggplot(lc, aes(x=variable,y=value,color=factor(replicate))) +

  # Adds individual data points
  geom_beeswarm(cex=3) +
  
  # Adds mean values as bars
  stat_summary(data = TotalAverages, fun = mean, fun.min = mean, fun.max = mean,
               geom = "crossbar", width = 0.25, color = "black") +
               
  # Adds error bars
  stat_summary(data = ReplicateAverages, fun.data = mean_se,
               geom = "errorbar", width = 0.1, color = "black", size= 1) +
               
  # Adds color palette
  scale_colour_manual(values=cbPalette) +
  
  # Adds Replicative averages as points (argument "cex" can be used to spread the data points if the averages are close together)
  geom_beeswarm(data=ReplicateAverages, size=5) +
  
  #Cosmetics and labeling
  theme_bw() + theme(axis.line = element_line(size = 1, colour = "black"),
                     legend.position = "none",
                     axis.title.y = element_text(family="Arial", size=28, color = "black", vjust = 2),
                     axis.text = element_text(family="Arial", size = 28, color = "black"),
                     axis.ticks = element_line(size = 1, color = "black"), 
                     axis.ticks.length = unit(2, "mm"),
                     panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(),
                     panel.background = element_blank(), 
                     panel.border = element_blank()) +
  xlab("") + ylab("Total counts")

lc

SPLEEN CHIL3

# Orders the variables on x-axis
sc$variable <- factor(sc$variable, levels = c("WT", "KO"))
# Casculates averages of each replicate
ReplicateAverages <- sc %>% group_by(variable, replicate) %>%
  summarise_each(list(mean))
ReplicateAverages
## # A tibble: 6 × 3
## # Groups:   variable [2]
##   variable replicate    value
##   <fct>        <dbl>    <dbl>
## 1 WT               1 0.000549
## 2 WT               2 0.00314 
## 3 WT               3 0.000857
## 4 KO               1 0.499   
## 5 KO               2 0.198   
## 6 KO               3 0.0982
# Gives the p-value for the t-Test of variable 1 and 2
ttest1 <- t.test(x=ReplicateAverages$value[1:3], y=ReplicateAverages$value[4:6],paired = FALSE, alternative="two.sided",var.equal = FALSE)
ttest1p <- ttest1[["p.value"]]
ttest1p
## [1] 0.1604201
# Casculates total averages
TotalAverages <- ReplicateAverages %>% summarise_each(list(mean))
TotalAverages
## # A tibble: 2 × 3
##   variable replicate   value
##   <fct>        <dbl>   <dbl>
## 1 WT               2 0.00152
## 2 KO               2 0.265
# Plots Superplot based on biological replicate averages
sc<-ggplot(sc, aes(x=variable,y=value,color=factor(replicate))) +

  # Adds individual data points
  geom_beeswarm(cex=3) +
  
  # Adds mean values as bars
  stat_summary(data = TotalAverages, fun = mean, fun.min = mean, fun.max = mean,
               geom = "crossbar", width = 0.25, color = "black") +
               
  # Adds error bars
  stat_summary(data = ReplicateAverages, fun.data = mean_se,
               geom = "errorbar", width = 0.1, color = "black", size= 1) +
               
  # Adds color palette
  scale_colour_manual(values=cbPalette) +
  
  # Adds Replicative averages as points (argument "cex" can be used to spread the data points if the averages are close together)
  geom_beeswarm(data=ReplicateAverages, size=5) +
  
  #Cosmetics and labeling
  theme_bw() + theme(axis.line = element_line(size = 1, colour = "black"),
                     legend.position = "none",
                     axis.title.y = element_text(family="Arial", size=28, color = "black", vjust = 2),
                     axis.text = element_text(family="Arial", size = 28, color = "black"),
                     axis.ticks = element_line(size = 1, color = "black"), 
                     axis.ticks.length = unit(2, "mm"),
                     panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(),
                     panel.background = element_blank(), 
                     panel.border = element_blank()) +
  xlab("") + ylab("Total counts")

sc

LIVER MPO

# Orders the variables on x-axis
lm$variable <- factor(lm$variable, levels = c("WT", "KO"))
# Calculates averages of each replicate
ReplicateAverages <- lm %>% group_by(variable, replicate) %>%
  summarise_each(list(mean))
ReplicateAverages
## # A tibble: 6 × 3
## # Groups:   variable [2]
##   variable replicate   value
##   <fct>        <dbl>   <dbl>
## 1 WT               1 0.00119
## 2 WT               2 0.00930
## 3 WT               3 0.00208
## 4 KO               1 0.00510
## 5 KO               2 0.00949
## 6 KO               3 0.0172
# Gives the p-value for the t-Test of variable 1 and 2
ttest1 <- t.test(x=ReplicateAverages$value[1:3], y=ReplicateAverages$value[4:6],paired = FALSE, alternative="two.sided",var.equal = FALSE)
ttest1p <- ttest1[["p.value"]]
ttest1p
## [1] 0.2230302
# Calculates total averages
TotalAverages <- ReplicateAverages %>% summarise_each(list(mean))
TotalAverages
## # A tibble: 2 × 3
##   variable replicate   value
##   <fct>        <dbl>   <dbl>
## 1 WT               2 0.00419
## 2 KO               2 0.0106
# Plots Superplot based on biological replicate averages
lm<-ggplot(lm, aes(x=variable,y=value,color=factor(replicate))) +

  # Adds individual data points
  geom_beeswarm(cex=3) +
  
  # Adds mean values as bars
  stat_summary(data = TotalAverages, fun = mean, fun.min = mean, fun.max = mean,
               geom = "crossbar", width = 0.25, color = "black") +
               
  # Adds error bars
  stat_summary(data = ReplicateAverages, fun.data = mean_se,
               geom = "errorbar", width = 0.1, color = "black", size= 1) +
               
  # Adds color palette
  scale_colour_manual(values=cbPalette) +
  
  # Adds Replicative averages as points (argument "cex" can be used to spread the data points if the averages are close together)
  geom_beeswarm(data=ReplicateAverages, size=5) +
  
  #Cosmetics and labeling
  theme_bw() + theme(axis.line = element_line(size = 1, colour = "black"),
                     legend.position = "none",
                     axis.title.y = element_text(family="Arial", size=28, color = "black", vjust = 2),
                     axis.text = element_text(family="Arial", size = 28, color = "black"),
                     axis.ticks = element_line(size = 1, color = "black"), 
                     axis.ticks.length = unit(2, "mm"),
                     panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(),
                     panel.background = element_blank(), 
                     panel.border = element_blank()) +
  xlab("") + ylab("Total counts")

lm

SPLEEN MPO

# Orders the variables on x-axis
sm$variable <- factor(sm$variable, levels = c("WT", "KO"))
# Casmulates averages of each replicate
ReplicateAverages <- sm %>% group_by(variable, replicate) %>%
  summarise_each(list(mean))
ReplicateAverages
## # A tibble: 6 × 3
## # Groups:   variable [2]
##   variable replicate   value
##   <fct>        <dbl>   <dbl>
## 1 WT               1 0.00156
## 2 WT               2 0.00245
## 3 WT               3 0.00222
## 4 KO               1 0.0641 
## 5 KO               2 0.0526 
## 6 KO               3 0.0155
# Gives the p-value for the t-Test of variable 1 and 2
ttest1 <- t.test(x=ReplicateAverages$value[1:3], y=ReplicateAverages$value[4:6],paired = FALSE, alternative="two.sided",var.equal = FALSE)
ttest1p <- ttest1[["p.value"]]
ttest1p
## [1] 0.1035329
# Casmulates total averages
TotalAverages <- ReplicateAverages %>% summarise_each(list(mean))
TotalAverages
## # A tibble: 2 × 3
##   variable replicate   value
##   <fct>        <dbl>   <dbl>
## 1 WT               2 0.00208
## 2 KO               2 0.0441
# Plots Superplot based on biological replicate averages
sm<-ggplot(sm, aes(x=variable,y=value,color=factor(replicate))) +

  # Adds individual data points
  geom_beeswarm(cex=3) +
  
  # Adds mean values as bars
  stat_summary(data = TotalAverages, fun = mean, fun.min = mean, fun.max = mean,
               geom = "crossbar", width = 0.25, color = "black") +
               
  # Adds error bars
  stat_summary(data = ReplicateAverages, fun.data = mean_se,
               geom = "errorbar", width = 0.1, color = "black", size= 1) +
               
  # Adds color palette
  scale_colour_manual(values=cbPalette) +
  
  # Adds Replicative averages as points (argument "cex" can be used to spread the data points if the averages are close together)
  geom_beeswarm(data=ReplicateAverages, size=5) +
  
  #Cosmetics and labeling
  theme_bw() + theme(axis.line = element_line(size = 1, colour = "black"),
                     legend.position = "none",
                     axis.title.y = element_text(family="Arial", size=28, color = "black", vjust = 2),
                     axis.text = element_text(family="Arial", size = 28, color = "black"),
                     axis.ticks = element_line(size = 1, color = "black"), 
                     axis.ticks.length = unit(2, "mm"),
                     panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(),
                     panel.background = element_blank(), 
                     panel.border = element_blank()) +
  xlab("") + ylab("Total counts")

sm

# Orders the variables on x-axis
tilen$variable <- factor(tilen$variable, levels = c("WT", "KO"))
# Calculates averages of each replicate
ReplicateAverages <- tilen %>% group_by(variable, replicate) %>%
  summarise_each(list(mean))
ReplicateAverages
## # A tibble: 6 × 3
## # Groups:   variable [2]
##   variable replicate  value
##   <fct>        <dbl>  <dbl>
## 1 WT               1 0.0390
## 2 WT               2 0.143 
## 3 WT               3 0.224 
## 4 KO               1 0.986 
## 5 KO               2 0.664 
## 6 KO               3 1.18
# Gives the p-value for the t-Test of variable 1 and 2
ttest1 <- t.test(x=ReplicateAverages$value[1:3], y=ReplicateAverages$value[4:6],paired = FALSE, alternative="two.sided",var.equal = FALSE)
ttest1p <- ttest1[["p.value"]]
ttest1p
## [1] 0.02312001
# Calculates total averages
TotalAverages <- ReplicateAverages %>% summarise_each(list(mean))
TotalAverages
## # A tibble: 2 × 3
##   variable replicate value
##   <fct>        <dbl> <dbl>
## 1 WT               2 0.135
## 2 KO               2 0.945
# Plots Superplot based on biological replicate averages
tilen<-ggplot(tilen, aes(x=variable,y=value,color=factor(replicate))) +

  # Adds individual data points
  geom_beeswarm(cex=3) +
  
  # Adds mean values as bars
  stat_summary(data = TotalAverages, fun = mean, fun.min = mean, fun.max = mean,
               geom = "crossbar", width = 0.25, color = "black") +
               
  # Adds error bars
  stat_summary(data = ReplicateAverages, fun.data = mean_se,
               geom = "errorbar", width = 0.1, color = "black", size= 1) +
               
  # Adds color palette
  scale_colour_manual(values=cbPalette) +
  
  # Adds Replicative averages as points (argument "cex" can be used to spread the data points if the averages are close together)
  geom_beeswarm(data=ReplicateAverages, size=5) +
  
  #Cosmetics and labeling
  theme_bw() + theme(axis.line = element_line(size = 1, colour = "black"),
                     legend.position = "none",
                     axis.title.y = element_text(family="Arial", size=28, color = "black", vjust = 2),
                     axis.text = element_text(family="Arial", size = 28, color = "black"),
                     axis.ticks = element_line(size = 1, color = "black"), 
                     axis.ticks.length = unit(2, "mm"),
                     panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(),
                     panel.background = element_blank(), 
                     panel.border = element_blank()) +
  xlab("") + ylab("Total counts")

tilen