# ========================================================= # PCA BIPLOT — LIME (12 Groups + High Vertical Space) # ========================================================= library(tidyverse) library(FactoMineR) library(factoextra) library(RColorBrewer) # 1. Import and Rename data <- read.csv("Lime_Pooled_Data.csv", header = TRUE) data <- data %>% rename( `Fruit Count` = NoFruits, `Fruit Weight (g)` = FruitWt_g, `Juice Content (%)` = JuiceContent_pct, `Shoot Length (cm)` = ShootLen_cm, `Shoot Count` = NoShoots, `Leaf Count` = NoLeaves, `Leaf Area (cm²)` = LeafArea_cm2, `Chlorophyll (SPAD)` = SPAD, `Days to Flowering` = DaysToFlower, `Flower Count` = NoFlowers, `TSS (°Brix)` = TSS_pct, `Acidity (%)` = Acidity_pct ) # 2. Create Treatment Factor data$Treatment <- factor(paste(data$PBZ, data$Light, sep = "_")) # 3. PCA Calculation pca_data <- data %>% select(where(is.numeric)) %>% select(-contains("Replication")) pca_res <- PCA(pca_data, scale.unit = TRUE, graph = FALSE) # 4. Manual Color Palette (P3_L2 changed) treatment_colors <- c( "P1_L1" = "#1b9e77", "P1_L2" = "#d95f02", "P1_L3" = "#7570b3", "P2_L1" = "#e7298a", "P2_L2" = "#66a61e", "P2_L3" = "#e6ab02", "P3_L1" = "#a6761d", "P3_L2" = "red", "P3_L3" = "#666666", "P4_L1" = "#1f78b4", "P4_L2" = "#33a02c", "P4_L3" = "#fb9a99" ) # 5. The Spacious Biplot pca_plot <- fviz_pca_biplot( pca_res, # --- Individuals --- geom.ind = "point", fill.ind = data$Treatment, col.ind = data$Treatment, pointshape = 21, pointsize = 3.5, addEllipses = TRUE, ellipse.type = "convex", alpha.ind = 0.4, # --- Variables --- label = "var", col.var = "black", labelsize = 5, repel = TRUE, arrowsize = 0.35, # thinner arrows alpha.var = 0.6, # lighter arrows max.overlaps = 200, force = 5, # --- Colors --- palette = treatment_colors ) + theme_bw(base_size = 14) + theme( plot.title = element_text(face = "bold", size = 16, hjust = 0.5), legend.title = element_text(face = "bold"), legend.text = element_text(size = 9), # Remove background grid lines panel.grid.major = element_blank(), panel.grid.minor = element_blank() ) + # --- Vertical Expansion --- coord_fixed(ratio = 5) + labs( title = "PCA Biplot: Lime Trait Distribution", x = "PC1 (98.7% Variance)", y = "PC2 (0.6% Variance)", fill = "Treatment", color = "Treatment" ) # Display print(pca_plot) # 6. Save ggsave("PCA_Lime_Spacious_12Groups.tiff", width = 13, height = 8, dpi = 400)