Clean up the environment

rm(list = ls())

Load required libraries for data reading, plotting, and data manipulation

library(readxl)       # For reading Excel files to import data
library(ggpubr)       # For creating publication-ready plots and charts
library(dplyr)        # For data manipulation
library(ggh4x)        # For advanced facetting functions in ggplot2

Load data

DietComp <- read_excel("Data/Data.xlsx", sheet = "DietComp")

Figure generation

Fig <- DietComp %>% mutate(Type = factor(Type, levels = c("Protein", "AA", "Ratio"))) %>%
          mutate(Diet = factor(Diet, levels = c("ALAC diet", "WPI diet", "Sow milk"),
                                        labels = c("ALAC formula", "WPI formula", "Sow milk"))) %>%
          ggdotchart(x = "Variable", y = "Value", 
                     color = "Diet", 
                     palette = c("turquoise3","purple", "orange"),
                     shape = 16, dot.size = 4,
                     xlab = "", ylab = "", add = "segments", position = position_dodge(0.1), rotate = TRUE) + 
                     facet_grid2(Type ~., scales = "free", independent = "x", space = "free_y") +
                     scale_y_continuous(expand = c(0, 0), limits = c(0, NA)) +
                     theme(strip.background = element_blank(), 
                           strip.text.y = element_blank())

# Save the figure to a pdf file:
ggsave(plot=Fig, height=3.5, width=7, dpi=300, filename="Figure 1/Fig1A.pdf", useDingbats=FALSE)

Fig

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] ggh4x_0.2.6   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    labeling_0.4.3    ragg_1.2.6       
## [49] utf8_1.2.4        munsell_0.5.1     broom_1.0.5       cachem_1.0.8