Clean up the environment
rm(list = ls())
Load necessary libraries for data reading, plotting, and statistical
analysis
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
Liver <- read_excel("Data/Data.xlsx", sheet = "Liver_targeted")
Brain <- read_excel("Data/Data.xlsx", sheet = "Brain_targeted")
Serum <- read_excel("Data/Data.xlsx", sheet = "Nec_serum_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") %>%
mutate(`KYN:TRP` = Kynurenine / Tryptophan) %>%
mutate(`(KYN+QUIN):TRP` = (Kynurenine + Quinolinate) / Tryptophan) %>%
select(Diet, `KYN:TRP`, `(KYN+QUIN):TRP`) %>%
mutate(Region = "Serum") %>%
pivot_longer(cols = c(`KYN:TRP`, `(KYN+QUIN):TRP`), names_to = "variable", values_to = "value") %>%
mutate(Class = "Serum")
Data.liver <- inner_join(Liver, PigInfo, by = "PigID") %>%
mutate(`KYN:TRP` = Kynurenine / Tryptophan) %>%
select(Diet, `KYN:TRP`) %>%
mutate(Region = "Liver") %>%
pivot_longer(cols = c(`KYN:TRP`), names_to = "variable", values_to = "value") %>%
mutate(Class = "Liver")
Data.brain <- inner_join(Brain, PigInfo, by = "PigID") %>%
mutate(`KYN:TRP` = Kynurenine / Tryptophan) %>%
select(Diet, Region, `KYN:TRP`) %>%
pivot_longer(cols = c(`KYN:TRP`), names_to = "variable", values_to = "value") %>%
mutate(Class = "Brain")
# Combine all data into a single dataset
All.data <- bind_rows(Data.serum, Data.liver, Data.brain) %>%
mutate(Region = factor(Region, levels = c("Serum", "Liver", "Hippocampus", "Hypothalamus", "PFC", "Striatum"))) %>%
mutate(Class = factor(Class, levels = c("Serum", "Liver", "Brain")))
Plotting data
Fig <- All.data %>% mutate(Diet = factor(Diet, levels = c("ALAC", "WPI", "SF"))) %>%
ggerrorplot(x = "variable", y = "value", color = "Diet",
palette = c("turquoise3","purple", "orange"),
na.rm = TRUE, xlab = "",
ylab ="Ratio", add = "mean_se", position = position_dodge(0.7)) +
facet_nested(.~ Class + Region , scales = "free") +
theme_classic()
Fig

# Save the figure in pdf format
ggsave(plot=Fig, height=4, width=10, dpi=300, filename="Figure 6/Fig6A.pdf", useDingbats=FALSE)
Group difference evaluation
All.data %>% group_by(Region, variable) %>%
wilcox_test(value ~ Diet, p.adjust.method = "none", paired = FALSE) %>% # Perform Wilcoxon test (Mann-Whitney U test)
select(-p.adj) %>%
add_significance(p.col = "p", cutpoints = c(0, 0.05, 0.1, 1), symbols = c("*", "#", "ns")) %>%
filter(p.signif != "ns") %>%
select(Region, variable, group1, group2, p, p.signif) %>%
kable() %>% # Print the tibble in a nicely formatted table
kable_styling(bootstrap_options = c("striped", "hover")) # Enhance table formatting with kableExtra
Region
|
variable
|
group1
|
group2
|
p
|
p.signif
|
Serum
|
(KYN+QUIN):TRP
|
ALAC
|
SF
|
0.001
|
|
Serum
|
(KYN+QUIN):TRP
|
SF
|
WPI
|
0.010
|
|
Serum
|
KYN:TRP
|
ALAC
|
SF
|
0.002
|
|
Serum
|
KYN:TRP
|
SF
|
WPI
|
0.002
|
|
Liver
|
KYN:TRP
|
ALAC
|
SF
|
0.078
|
#
|
Liver
|
KYN:TRP
|
SF
|
WPI
|
0.007
|
|
PFC
|
KYN:TRP
|
ALAC
|
SF
|
0.078
|
#
|
PFC
|
KYN:TRP
|
ALAC
|
WPI
|
0.091
|
#
|
PFC
|
KYN:TRP
|
SF
|
WPI
|
0.010
|
|
Striatum
|
KYN:TRP
|
ALAC
|
SF
|
0.078
|
#
|
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