Clean up the environment
rm(list = ls())
Load libraries for data reading, plotting, statistical analysis
library(readxl) # For reading Excel files
library(ggpubr) # For creating publication-ready plots
library(dplyr) # For data manipulation
library(rstatix) # For statistical tests and adding significance markers
library(knitr) # For displaying tibbles in a nicely formatted table
library(kableExtra) # For enhancing table formatting
Load data
# Load pig information and measurement of anemia status
PigInfo <- read_excel("Data/Data.xlsx", sheet = "PigInfo")
Anemia <- read_excel("Data/Data.xlsx", sheet = "Hb_and_Hct")
Plot Hct and Hb
Fig1 <- Anemia %>%
filter(!PigID %in% c(19, 24)) %>% ## Remove the two piglets where the blood in the heparin tube heavily coagulated
inner_join(PigInfo, by = "PigID") %>%
mutate(Diet = factor(Diet, levels = c("ALAC", "WPI", "SF"))) %>%
ggboxplot(y = "Hct", x = "Diet",
fill = "Diet", palette = c("turquoise3","purple", "orange"),
xlab = "", ylab = "Hct", add = "jitter")
Fig2 <- Anemia %>%
filter(!PigID %in% c(19, 24)) %>% ## Remove the two piglets where the blood in the heparin tube heavily coagulated
inner_join(PigInfo, by = "PigID") %>%
mutate(Diet = factor(Diet, levels = c("ALAC", "WPI", "SF"))) %>%
mutate(Hb = Hb/10) %>% # Hb was in g/L, convert unit
ggboxplot(y = "Hb", x = "Diet", fill = "Diet",
palette = c("turquoise3","purple", "orange"),
xlab = "", ylab = "Hb (g/dL)", add = "jitter")
Fig.all <- ggarrange(Fig1, Fig2, common.legend = TRUE)
Fig.all

# Save the figure in pdf:
ggsave(plot=Fig.all, height=4, width=7.5, dpi=300, filename="SI Figure 2/SI.Fig2.pdf", useDingbats=FALSE)
Statistical analysis via Tukey HSD
Anemia %>% filter(!PigID %in% c(19, 24)) %>% ## Remove the two piglets where the blood in the heparin tube heavily coagulated
inner_join(PigInfo, by = "PigID") %>%
mutate(Diet = factor(Diet, levels = c("ALAC", "WPI", "SF"))) %>%
tukey_hsd(Hb ~ Diet) %>%
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
|
WPI
|
0
|
-1.26083
|
-32.25921
|
29.73755
|
0.994
|
ns
|
Diet
|
ALAC
|
SF
|
0
|
-13.32532
|
-52.97859
|
26.32795
|
0.683
|
ns
|
Diet
|
WPI
|
SF
|
0
|
-12.06449
|
-50.60054
|
26.47156
|
0.718
|
ns
|
Anemia %>% filter(!PigID %in% c(19, 24)) %>% ## Remove the two piglets where the blood in the heparin tube heavily coagulated
inner_join(PigInfo, by = "PigID") %>%
mutate(Diet = factor(Diet, levels = c("ALAC", "WPI", "SF"))) %>%
tukey_hsd(Hct ~ Diet) %>%
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
|
WPI
|
0
|
-0.0916667
|
-7.173774
|
6.990441
|
0.999
|
ns
|
Diet
|
ALAC
|
SF
|
0
|
-4.8000000
|
-13.859463
|
4.259463
|
0.396
|
ns
|
Diet
|
WPI
|
SF
|
0
|
-4.7083333
|
-13.512548
|
4.095882
|
0.390
|
ns
|
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 dplyr_1.1.3
## [5] 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] gridExtra_2.3 digest_0.6.33 stringi_1.7.12 cowplot_1.1.1
## [45] grid_4.2.2 cli_3.6.2 tools_4.2.2 magrittr_2.0.3
## [49] sass_0.4.7 tibble_3.2.1 tidyr_1.3.0 car_3.1-2
## [53] pkgconfig_2.0.3 xml2_1.3.5 rmarkdown_2.28 svglite_2.1.2
## [57] httr_1.4.7 rstudioapi_0.15.0 R6_2.5.1 compiler_4.2.2