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(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 hormonal data
PP_hormones <- read_excel("Data/Data.xlsx", sheet = "PP_hormones")
Nec_hormones <- read_excel("Data/Data.xlsx", sheet = "Nec_hormones")
# Load pig information
PigInfo <- read_excel("Data/Data.xlsx", sheet = "PigInfo")
Data organization
PP.data <- PP_hormones %>% inner_join(PigInfo, by = "PigID") %>%
mutate(Day = "Day 11 or 12") %>%
select(Diet, Day, Cortisol, TimePoint)
Nec.data <- Nec_hormones %>% inner_join(PigInfo, by = "PigID") %>%
mutate(Day = "Day 16") %>%
mutate(TimePoint = "") %>%
select(Diet, Day, Cortisol, TimePoint)
# Combine postprandial and necropsy data
All.data <- bind_rows(PP.data, Nec.data) %>%
mutate(Diet = factor(Diet, levels = c("ALAC", "WPI", "SF"))) %>%
mutate(TimePoint = factor(TimePoint, levels = c("baseline", "30 min", "60 min", "120 min")))
Plotting cortisol levels by diet and time point
Fig <- All.data %>% ggerrorplot(x = "TimePoint", y = "Cortisol", color = "Diet",
palette = c("turquoise3","purple", "orange"),
na.rm = TRUE, xlab = "",
ylab ="Cortisol (ug/L)", add = "mean_se", position = position_dodge(0.6)) +
facet_nested(.~ Day , scales = "free", space = "free_x") +
theme_classic()
Fig

# Save the figure in pdf format
ggsave(plot=Fig, height=4, width=6, dpi=300, filename="Figure 6/Fig6C.pdf", useDingbats=FALSE)
Group difference evaluation
All.data %>% group_by(TimePoint) %>%
wilcox_test(Cortisol ~ Diet, p.adjust.method = "none", paired = FALSE) %>% # Perform Wilcoxon test (Mann-Whitney U test)
select(-p.adj) %>%
add_significance(cutpoints = c(0, 0.05, 0.1, 1), symbols = c("*", "#", "ns")) %>%
select(TimePoint, 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
TimePoint
|
group1
|
group2
|
p
|
p.signif
|
baseline
|
ALAC
|
WPI
|
0.970
|
ns
|
30 min
|
ALAC
|
WPI
|
0.093
|
#
|
60 min
|
ALAC
|
WPI
|
0.009
|
|
120 min
|
ALAC
|
WPI
|
0.465
|
ns
|
NA
|
ALAC
|
WPI
|
0.089
|
#
|
NA
|
ALAC
|
SF
|
0.879
|
ns
|
NA
|
WPI
|
SF
|
0.049
|
|
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] dplyr_1.1.3 ggpubr_0.6.0 ggplot2_3.5.1 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] tidyr_1.3.0 car_3.1-2 pkgconfig_2.0.3 xml2_1.3.5
## [53] rmarkdown_2.28 svglite_2.1.2 httr_1.4.7 rstudioapi_0.15.0
## [57] R6_2.5.1 compiler_4.2.2