Clean up the environment
rm(list = ls())
Load necessary 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
Load data
# Load untargeted postprandial serum metabolome and pig information
PP.untargeted.serum <- read_excel("Data/Data.xlsx", sheet = "PP_serum_untargetedMS")
PigInfo <- read_excel("Data/Data.xlsx", sheet = "PigInfo")
Data organization and transformation
#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)
}
# list of metabolites to remove (likely due to mis-identification)
variables_to_remove <- c("1-monopalmitin", "1-monostearin", "3-Aminopiperidine-2,6-dione", "3,6-anhydro-D-galactose", "arachidonic acid", "behenic acid", "beta-sitosterol", "campesterol", "cholesterol", "dihydrocholesterol", "docosahexaenoic acid", "erythritol", "erythrose", "fructose", "glycerol-alpha-phosphate", "heptadecanoic acid", "linoleic acid", "linolenic acid", "lyxose", "maltitol", "methanolphosphate", "myristic acid", "oleic acid", "palmitic acid", "palmitoleic acid", "salicylic acid", "tagatose", "threose", "tocopherol alpha-", "tocopherol gamma-", "undecanoic acid", "xylitol", "xylose")
Metabolome <- PP.untargeted.serum %>%
inner_join(PigInfo, by = "PigID") %>%
select(-all_of(variables_to_remove)) %>%
mutate(across(`1,5-anhydroglucitol` : `68`, .fns = list(log = glog), .names = "{.col}_{.fn}")) %>%
mutate(Group = paste(Diet, TimePoint, sep = " ")) %>%
mutate(Group = factor(Group, levels = c("ALAC baseline", "ALAC 30 min", "ALAC 60 min", "ALAC 120 min",
"WPI baseline", "WPI 30 min", "WPI 60 min", "WPI 120 min")))
Metabolome.log <- Metabolome %>% select(`1,5-anhydroglucitol_log`:`xylulose_log`)
PCA plot
PCA <- mixOmics::pca(Metabolome.log, ncomp = 5, scale = T, center = T)
df <- data.frame(pc1 = PCA$variates$X[,1],
pc2 = PCA$variates$X[,2],
Group = Metabolome$Group)
Centroids.x <- aggregate(pc1~Group, df, mean)
Centroids.y <- aggregate(pc2~Group, df, mean)
Centroids <- inner_join(Centroids.x, Centroids.y, by = "Group") %>%
rename(pc1.mean = pc1) %>%
rename(pc2.mean = pc2)
df <- df %>% inner_join(Centroids, by = "Group")
Fig <- ggplot(df, aes(x = pc1, y = pc2, colour = Group)) +
geom_point(size=1.5) +
xlab(paste("PC1 (", round(unlist(PCA$prop_expl_var)[1]*100,1), "%)", sep="")) +
ylab(paste("PC2 (", round(unlist(PCA$prop_expl_var)[2]*100,1), "%)", sep="")) +
geom_point(aes(x=pc1.mean, y=pc2.mean),size=3, shape = 1) +
geom_segment(aes(x=pc1.mean, y=pc2.mean, xend=pc1, yend=pc2), alpha = 0.6) +
scale_color_manual(values = c(
"#A50026FF", "#D73027FF", "#F46D43FF", "#FDAE61FF",
"#002BFFFF", "#1A66FFFF", "#3399FFFF", "#66CCFFFF")) +
theme_bw() +
theme(axis.line = element_line(colour = "black"),
plot.title = element_text(hjust = 0.5),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_text(size = 12),
axis.text.x = element_text(size = 11),
axis.text.y = element_text(size = 11),
panel.background = element_rect(colour = "black", linewidth=0.5))
Fig

# Save the figure in pdf format:
ggsave(plot=Fig, height=4, width=7.5, dpi=300, filename="SI Figure 4/SI.Fig4.pdf", useDingbats=FALSE)
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] dplyr_1.1.3 ggpubr_0.6.0 ggplot2_3.5.1 readxl_1.4.3
##
## loaded via a namespace (and not attached):
## [1] ggrepel_0.9.4 Rcpp_1.0.11 lattice_0.20-45
## [4] tidyr_1.3.0 corpcor_1.6.10 digest_0.6.33
## [7] utf8_1.2.4 RSpectra_0.16-1 plyr_1.8.9
## [10] R6_2.5.1 cellranger_1.1.0 backports_1.4.1
## [13] ellipse_0.5.0 evaluate_1.0.1 highr_0.10
## [16] pillar_1.9.0 rlang_1.1.2 rstudioapi_0.15.0
## [19] car_3.1-2 jquerylib_0.1.4 Matrix_1.5-4.1
## [22] rmarkdown_2.28 textshaping_0.3.7 labeling_0.4.3
## [25] rARPACK_0.11-0 BiocParallel_1.32.6 stringr_1.5.1
## [28] igraph_1.5.1 munsell_0.5.1 broom_1.0.5
## [31] compiler_4.2.2 xfun_0.40 systemfonts_1.0.5
## [34] pkgconfig_2.0.3 htmltools_0.5.6.1 tidyselect_1.2.0
## [37] tibble_3.2.1 gridExtra_2.3 codetools_0.2-19
## [40] matrixStats_1.0.0 fansi_1.0.6 withr_3.0.1
## [43] MASS_7.3-60 grid_4.2.2 jsonlite_1.8.8
## [46] gtable_0.3.5 lifecycle_1.0.4 magrittr_2.0.3
## [49] scales_1.3.0 stringi_1.7.12 cli_3.6.2
## [52] cachem_1.0.8 carData_3.0-5 farver_2.1.1
## [55] ggsignif_0.6.4 reshape2_1.4.4 bslib_0.5.1
## [58] ragg_1.2.6 generics_0.1.3 vctrs_0.6.5
## [61] RColorBrewer_1.1-3 mixOmics_6.22.0 tools_4.2.2
## [64] glue_1.6.2 purrr_1.0.2 abind_1.4-5
## [67] parallel_4.2.2 fastmap_1.1.1 yaml_2.3.7
## [70] colorspace_2.1-0 rstatix_0.7.2 knitr_1.45
## [73] sass_0.4.7