Clean up the environment

rm(list = ls())

Load library

library(readxl)       # For reading Excel files
library(ggpubr)       # For creating publication-ready plots
library(dplyr)        # For data manipulation
library(tidyr)        # For reshaping data
library(ggh4x)        # For advanced faceting functions in ggplot2
library(rstatix)      # For statistical tests and adding significance markers
library(knitr)        # For displaying tibbles in a nice table format
library(kableExtra)   # For enhancing table formatting

Load data

# Load targeted serum, liver and brain data
Serum <- read_excel("Data/Data.xlsx", sheet = "Nec_serum_targeted")
Liver <- read_excel("Data/Data.xlsx", sheet = "Liver_targeted")
Brain <- read_excel("Data/Data.xlsx", sheet = "Brain_targeted")

# Load pig information and necropsy metadata
PigInfo <- read_excel("Data/Data.xlsx", sheet = "PigInfo")
Nec_metadata <- read_excel("Data/Data.xlsx", sheet = "Nec_metadata")

Data organization

Data.serum <- inner_join(Serum, PigInfo, by = "PigID") %>%
               select(Diet, Serotonin) %>%
               mutate(Region = "Serum") %>%
               pivot_longer(cols = Serotonin, names_to = "variable", values_to = "value") %>%
               mutate(Class = "I")


Data.liver <- inner_join(Liver, PigInfo, by = "PigID") %>%
               select(Diet, Serotonin) %>%
               mutate(Region = "Liver") %>%
               pivot_longer(cols = Serotonin, names_to = "variable", values_to = "value") %>%
               mutate(Class = "II")

Data.brain <- inner_join(Brain, PigInfo, by = "PigID") %>%
               select(Diet, Region, Serotonin) %>%
               pivot_longer(cols = Serotonin, names_to = "variable", values_to = "value") %>%
               mutate(Class = "II")
# Combine serum, liver, and brain data
All.data <- bind_rows(Data.serum, Data.liver, Data.brain) %>%
              mutate(Region = factor(Region, levels = c("Serum", "Liver", "Hippocampus", "Hypothalamus", "PFC", "Striatum")))

Plotting data for serotonin concentration by diet and sample type

Fig <- All.data %>% 
          mutate(Diet = factor(Diet, levels = c("ALAC", "WPI", "SF"))) %>%
          ggerrorplot(x = "Region", y = "value", color = "Diet", 
                      palette = c("turquoise3","purple", "orange"),
                      na.rm = TRUE, xlab = "", 
                      ylab ="Serotonin concentration",  add = "mean_se", position = position_dodge(0.7)) +
          facet_grid2(.~ Class , scales = "free", independent = "y", space = "free_x") + 
          theme_classic() +
          theme(strip.background = element_blank(), strip.text.x = element_blank())


Fig

# Save the figure in pdf format:
ggsave(plot=Fig, height=4, width=7.5, dpi=300, filename="Figure 5/Fig5C.pdf", useDingbats=FALSE)

Group difference evaluation

#This function transforms the input values by the generalized #log function.
glog <- function(y) {
  #Using lambda = 1 
  yt <- log(y+sqrt(y^2+1))
  return(yt)
}

ALAC vs WPI: Serum and liver data, adjusting for intake volume and postprandial time

Serum %>% inner_join(PigInfo, by = "PigID") %>%
          inner_join(Nec_metadata, by = "PigID") %>%
            filter(Diet %in% c("ALAC", "WPI")) %>%
            mutate(glog.5HT = glog(Serotonin * 10)) %>% # glog transformation
            anova_test(glog.5HT ~ Diet + SowID + Formula.consumed.g + Time.postprandial.min, type = 1)
## ANOVA Table (type I tests)
## 
##                  Effect DFn DFd     F     p p<.05   ges
## 1                  Diet   1  17 4.599 0.047     * 0.213
## 2                 SowID   2  17 2.603 0.103       0.234
## 3    Formula.consumed.g   1  17 1.070 0.315       0.059
## 4 Time.postprandial.min   1  17 0.890 0.359       0.050
Liver %>% inner_join(PigInfo, by = "PigID") %>%
          inner_join(Nec_metadata, by = "PigID") %>%
            filter(Diet %in% c("ALAC", "WPI")) %>%
            mutate(glog.5HT = glog(Serotonin * 10)) %>% # glog transformation
            anova_test(glog.5HT ~ Diet + SowID + Formula.consumed.g + Time.postprandial.min, type = 1)
## ANOVA Table (type I tests)
## 
##                  Effect DFn DFd      F     p p<.05   ges
## 1                  Diet   1  17 12.250 0.003     * 0.419
## 2                 SowID   2  17  3.989 0.038     * 0.319
## 3    Formula.consumed.g   1  17  3.372 0.084       0.166
## 4 Time.postprandial.min   1  17  3.756 0.069       0.181

Between formula-fed groups and SF, adjusting for sow ID

Serum %>% inner_join(PigInfo, by = "PigID") %>%
            mutate(glog.5HT = glog(Serotonin * 10)) %>% # glog transformation
            tukey_hsd(glog.5HT ~ Diet + SowID) %>% # Perform Tukey HSD test
            filter(term == "Diet") %>%
            add_significance(p.col = "p.adj", cutpoints = c(0, 0.05, 0.1, 1), symbols = c("*", "#", "ns")) %>%
            kable() %>% # Print the tibble in a nicely formatted table
            kable_styling(bootstrap_options = c("striped", "hover")) # Enhance table formatting with kableExtra
term group1 group2 null.value estimate conf.low conf.high p.adj p.adj.signif
Diet ALAC SF 0 -0.0124378 -0.1075306 0.0826551 0.9430 ns
Diet ALAC WPI 0 0.0736019 -0.0046099 0.1518137 0.0678 #
Diet SF WPI 0 0.0860397 -0.0076443 0.1797236 0.0761 #
Liver %>% inner_join(PigInfo, by = "PigID") %>%
            mutate(glog.5HT = glog(Serotonin * 10)) %>% # glog transformation
            tukey_hsd(glog.5HT ~ Diet + SowID) %>% # Perform Tukey HSD test
            filter(term == "Diet") %>%
            add_significance(p.col = "p.adj", cutpoints = c(0, 0.05, 0.1, 1), symbols = c("*", "#", "ns")) %>%
            kable() %>% # Print the tibble in a nicely formatted table
            kable_styling(bootstrap_options = c("striped", "hover")) # Enhance table formatting with kableExtra
term group1 group2 null.value estimate conf.low conf.high p.adj p.adj.signif
Diet ALAC SF 0 -0.0085270 -0.3616942 0.3446403 0.99800 ns
Diet ALAC WPI 0 0.3940348 0.1035624 0.6845072 0.00662
Diet SF WPI 0 0.4025618 0.0546269 0.7504967 0.02120

Brain data, adjusting for sow ID

Brain %>% inner_join(PigInfo, by = "PigID") %>%
            mutate(glog.5HT = glog(Serotonin * 10)) %>% # Applying glog transformation
            group_by(Region) %>%
            tukey_hsd(glog.5HT ~ Diet + SowID) %>% # Perform Tukey HSD test
            filter(term == "Diet") %>%
            add_significance(p.col = "p.adj", cutpoints = c(0, 0.05, 0.1, 1), symbols = c("*", "#", "ns")) %>%
            filter(p.adj.signif != "ns") %>%
            select(Region, group1, group2, p.adj, p.adj.signif) %>%
            kable() %>% # Print the tibble in a nicely formatted table
            kable_styling(bootstrap_options = c("striped", "hover")) # Enhance table formatting with kableExtra
Region group1 group2 p.adj p.adj.signif
Hypothalamus ALAC SF 0.0785 #
Hypothalamus SF WPI 0.0509 #
PFC SF WPI 0.0489
Striatum ALAC WPI 0.0628 #
sessionInfo()
## R version 4.2.2 (2022-10-31)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Big Sur ... 10.16
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] kableExtra_1.3.4 knitr_1.45       rstatix_0.7.2    ggh4x_0.2.6     
## [5] tidyr_1.3.0      dplyr_1.1.3      ggpubr_0.6.0     ggplot2_3.5.1   
## [9] readxl_1.4.3    
## 
## loaded via a namespace (and not attached):
##  [1] tidyselect_1.2.0  xfun_0.40         bslib_0.5.1       purrr_1.0.2      
##  [5] carData_3.0-5     colorspace_2.1-0  vctrs_0.6.5       generics_0.1.3   
##  [9] viridisLite_0.4.2 htmltools_0.5.6.1 yaml_2.3.7        utf8_1.2.4       
## [13] rlang_1.1.2       jquerylib_0.1.4   pillar_1.9.0      glue_1.6.2       
## [17] withr_3.0.1       lifecycle_1.0.4   stringr_1.5.1     munsell_0.5.1    
## [21] ggsignif_0.6.4    gtable_0.3.5      cellranger_1.1.0  ragg_1.2.6       
## [25] rvest_1.0.3       evaluate_1.0.1    labeling_0.4.3    fastmap_1.1.1    
## [29] fansi_1.0.6       highr_0.10        broom_1.0.5       scales_1.3.0     
## [33] backports_1.4.1   cachem_1.0.8      webshot_0.5.5     jsonlite_1.8.8   
## [37] abind_1.4-5       farver_2.1.1      systemfonts_1.0.5 textshaping_0.3.7
## [41] digest_0.6.33     stringi_1.7.12    grid_4.2.2        cli_3.6.2        
## [45] tools_4.2.2       magrittr_2.0.3    sass_0.4.7        tibble_3.2.1     
## [49] car_3.1-2         pkgconfig_2.0.3   xml2_1.3.5        rmarkdown_2.28   
## [53] svglite_2.1.2     httr_1.4.7        rstudioapi_0.15.0 R6_2.5.1         
## [57] compiler_4.2.2