### Figure4.R ### Visualizing root dry mass over time for cuttings grown in different soils and environments. ### Script for: # "Restoring South African subtropical succulent thicket using # Portulacaria afra: rooting variation across three soil types" # Authors: AJ Potts, D Liddell, C Clarke, N Galuszynski # --- Setup Libraries and Environment --- library(groundhog) # Ensures reproducible package versions set.groundhog.folder("C:\\Groundhog_R\\R4.4.1_2024-05-14") # Sets folder for storing library versions GroundhogDay <- '2024-05-14' # Snapshot date for reproducibility groundhog.library("tidyverse", GroundhogDay) # Load Tidyverse for data handling # --- Define Working Directory --- # Replace this path with the location of your data setwd("D:\\Google Drive\\0_SpekboomResearchGroup2.0\\3_Experiments\\NMU22(07)SoilRootingExperiment\\DataForSubmission/") # --- Load and Prepare Data --- # Load the experimental data dat <- read_csv("NMU22(07)SoilRootingExperiment_data.csv") # Modify the Harvest column and create labels for plotting dat <- dat %>% mutate( Harvest = Harvest * 7 + 7, # Convert weeks to days after planting HarvestLabel = factor(Harvest, levels = 1:7 * 7 + 7, labels = paste0(1:7 * 7 + 7, " days after planting")) ) # --- Calculate Summary Statistics --- # Filter, group, and calculate mean, SE, and error bars for Root Dry Mass summary_data <- dat %>% filter(RootDryMass_g < 0.5) %>% # Exclude outliers above 0.5g group_by(SiteCode, Harvest, Environment) %>% summarise( uRootDryMass = mean(RootDryMass_g), # Mean root dry mass n = n(), # Sample size se = sd(RootDryMass_g) / sqrt(n - 1), # Standard error ymin = uRootDryMass - se, # Lower error bar ymax = uRootDryMass + se # Upper error bar ) %>% ungroup() %>% mutate( Harvest = ifelse(Environment == "Glasshouse", Harvest - 0.1, Harvest + 0.1) # Adjust Harvest for clarity ) # --- Generate Plot --- plot <- ggplot(summary_data, aes(Harvest, uRootDryMass, colour = Environment, linetype = Environment)) + geom_line(size = 1.5) + # Add lines geom_errorbar(aes(ymin = ymin, ymax = ymax), size = 0.8, width = 2) + # Add error bars geom_point(size = 2) + # Add points scale_colour_manual(values = c("darkgrey", "black"), name = "Experiment") + scale_linetype_manual(values = c(1, 2), name = "Experiment") + facet_wrap(~SiteCode) + # Separate plots by SiteCode scale_x_continuous(breaks = seq(14, 14 * 7, by = 7)) + # Custom x-axis ticks ylab("Root Dry Mass (g)") + xlab("Days after planting") + theme_bw() + # Set theme theme( legend.position = c(0.9, 0.99), legend.justification = c("right", "top"), legend.box.just = "right", legend.margin = margin(6, 6, 6, 6), legend.box.background = element_rect(colour = "black") ) plot # Save the plot as a high-quality image ggsave("Figure4.jpg", plot = plot, units = "cm", width = 18, height = 11)