Clean up the environment

rm(list = ls())

Load necessary libraries for data reading and plotting

library(readxl)       # For reading Excel files
library(ggpubr)       # For creating publication-ready plots
library(dplyr)        # For data manipulation

Load data

# Load targeted serum metabolome data and pig information
PP.targeted.serum <- read_excel("Data/Data.xlsx", sheet = "PP_serum_MS")
PigInfo <- read_excel("Data/Data.xlsx", sheet = "PigInfo")

Data organization

Fig <- PP.targeted.serum %>% inner_join(PigInfo, by = "PigID") %>%
                                select(PigID, Diet, TimePoint, Tryptophan) %>%
                                group_by(PigID) %>%
                                filter(n() == 4) %>% #Select those piglets with all 4 timepoints
                                ungroup() %>%
                                mutate(TimePoint = factor(TimePoint, levels = c("baseline", "30 min", "60 min", "120 min"))) %>%
                                mutate(Diet = factor(Diet, levels = c("ALAC", "WPI"))) %>%
                                mutate(PigID = factor(PigID)) %>%
                                ggplot(aes(x = TimePoint, y = Tryptophan, group = PigID, color = Diet)) +
                                  geom_point(size = 1, position = position_dodge(width = 0.2)) +
                                  geom_line(linewidth = 0.7, position = position_dodge(width = 0.2)) +
                                  scale_color_manual(values = c("turquoise3", "purple")) +
                                  labs(y = "Tryptophan (uM)", x = "") +
                                  theme_classic2()

Fig

# for identifying pig ID
PP.targeted.serum %>% inner_join(PigInfo, by = "PigID") %>%
                          select(PigID, Diet, TimePoint, Tryptophan) %>%
                          group_by(PigID) %>%
                          filter(n() == 4) %>% #Select those piglets with all 4 timepoints
                          ungroup() %>%
                          mutate(TimePoint = factor(TimePoint, levels = c("baseline", "30 min", "60 min", "120 min"))) %>%
                          mutate(Diet = factor(Diet, levels = c("ALAC", "WPI"))) %>%
                          mutate(PigID = factor(PigID)) %>%
                          ggplot(aes(x = TimePoint, y = Tryptophan, group = PigID, color = PigID)) +
                            geom_point(size = 1, position = position_dodge(width = 0.2)) +
                            geom_line(linewidth = 0.7, position = position_dodge(width = 0.2)) +
                            labs(y = "Tryptophan (uM)", x = "") +
                            theme_classic2()

# Save the figure in pdf format:
ggsave(plot=Fig, height=4, width=5.5, dpi=300, filename="SI Figure 5/SI.Fig5.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] highr_0.10        cellranger_1.1.0  bslib_0.5.1       compiler_4.2.2   
##  [5] pillar_1.9.0      jquerylib_0.1.4   tools_4.2.2       digest_0.6.33    
##  [9] jsonlite_1.8.8    evaluate_1.0.1    lifecycle_1.0.4   tibble_3.2.1     
## [13] gtable_0.3.5      pkgconfig_2.0.3   rlang_1.1.2       cli_3.6.2        
## [17] rstudioapi_0.15.0 yaml_2.3.7        xfun_0.40         fastmap_1.1.1    
## [21] withr_3.0.1       knitr_1.45        systemfonts_1.0.5 generics_0.1.3   
## [25] sass_0.4.7        vctrs_0.6.5       grid_4.2.2        tidyselect_1.2.0 
## [29] glue_1.6.2        R6_2.5.1          textshaping_0.3.7 rstatix_0.7.2    
## [33] fansi_1.0.6       rmarkdown_2.28    carData_3.0-5     farver_2.1.1     
## [37] car_3.1-2         tidyr_1.3.0       purrr_1.0.2       magrittr_2.0.3   
## [41] backports_1.4.1   scales_1.3.0      htmltools_0.5.6.1 abind_1.4-5      
## [45] colorspace_2.1-0  ggsignif_0.6.4    ragg_1.2.6        labeling_0.4.3   
## [49] utf8_1.2.4        munsell_0.5.1     broom_1.0.5       cachem_1.0.8