# 1. Load libraries library(ggplot2) library(dplyr) library(tidyr) # 2. Load and Combine Data y1 <- read.csv("Lime_Year1_Data.csv") y2 <- read.csv("Lime_Year2_Data.csv") df_combined <- rbind(y1, y2) # 3. Reshape and Rename Metrics df_long <- df_combined %>% select(Year, Light, PBZ, DaysToFlower, NoFlowers, NoFruits, FruitWt_g) %>% pivot_longer( cols = c(DaysToFlower, NoFlowers, NoFruits, FruitWt_g), names_to = "Metric", values_to = "Value" ) %>% mutate( Metric = recode(Metric, "DaysToFlower" = "Days to Flower", "NoFlowers" = "No. of Flowers", "NoFruits" = "No. of Fruits", "FruitWt_g" = "Fruit Weight (g)") ) # 4. Set Factor Levels df_long <- df_long %>% mutate( PBZ = factor(PBZ, levels = c("P0", "P1", "P2", "P3")), Light = factor(Light, levels = c("L1", "L2", "L3")), Metric = factor(Metric, levels = c("Days to Flower", "No. of Flowers", "No. of Fruits", "Fruit Weight (g)")), Year = factor(Year) ) # 5. Calculate Mean and SEM plot_summary <- df_long %>% group_by(Year, Light, PBZ, Metric) %>% summarise( mean_val = mean(Value, na.rm = TRUE), se_val = sd(Value, na.rm = TRUE) / sqrt(n()), .groups = "drop" ) # 6. Generate Multi-Variable Plot ggplot(plot_summary, aes(x = PBZ, y = mean_val, color = Light, group = interaction(Light, Year))) + geom_line(aes(linetype = Year), linewidth = 0.8) + geom_point(aes(shape = Year), size = 2) + geom_errorbar(aes(ymin = mean_val - se_val, ymax = mean_val + se_val), width = 0.2, alpha = 0.7) + facet_grid(Metric ~ Light, scales = "free_y") + labs( title = "Lime Phenology & Yield: PBZ and Light Intensity Effects", x = "PBZ Concentration", y = "Mean Value", color = "Light Intensity", linetype = "Study Year", shape = "Study Year" ) + theme_bw() + theme( legend.position = "bottom", strip.text = element_text(face = "bold", size = 10), strip.background = element_blank(), # removes boxes around facet titles panel.grid.major = element_blank(), panel.grid.minor = element_blank(), axis.line = element_line(colour = "black") )