library(groundhog) set.groundhog.folder("C:\\Groundhog_R\\R4.2.3_2023-04-01") GroundhogDay <- '2023-04-01' groundhog.library("dplyr",GroundhogDay) groundhog.library("ggplot2",GroundhogDay) groundhog.library("ggrepel",GroundhogDay) groundhog.library("lubridate",GroundhogDay) groundhog.library("tibble",GroundhogDay) groundhog.library("tidyr",GroundhogDay) groundhog.library("cmartin/ggConvexHull",GroundhogDay) groundhog.library("ggpmisc",GroundhogDay) setwd("D:\\Google Drive\\0_SpekboomResearchGroup2.0\\3_Experiments\\RegionalTransect21(10)_ParentPlantMaterialExperiment\\manuscript/") read.csv("data_manuscript/harvestdata_2023-08-29.csv")%>% as_tibble()-> dat_all read.csv("data_manuscript/parentplantleafmoisturedata_2023-08-29.csv")%>% as_tibble()-> dat_pp read.csv("data_manuscript/harvest_days.csv")%>% as_tibble()-> harvestdates dat_all%>% mutate(Site=factor(Site,labels=paste("Site:",1:10)))-> dat_all dat_pp%>% mutate(Site=factor(Site,labels=paste("Site:",1:10)))-> dat_pp dat_all%>% filter(SamplingEvent%in%c(4,5,6,7,8))%>% group_by(SamplingEvent,Site,Individual)%>% summarise(uRootMass=mean(RootMass,na.rm=T), uLeafMoisture=mean(LeafMoisture,na.rm=T))%>% filter(!is.na(uRootMass))%>% filter(!is.na(uLeafMoisture))%>% left_join(harvestdates)%>% left_join( dplyr::select(dat_pp,Site,Individual,LeafMoisture)%>% group_by(Site,Individual)%>% summarise(LeafMoisture=mean(LeafMoisture)))%>% mutate(DaysSincePlanting=factor(DaysSincePlanting,levels=c(35,42,48,56,103), labels=c("35 days","42 days","48 days","56 days","103 days")))-> forGG forGG%>% ungroup()%>% select(Site,Individual,LeafMoisture,uRootMass,DaysSincePlanting)%>% group_by(Individual,Site,DaysSincePlanting)%>% summarise(LeafMoisture=mean(LeafMoisture), uRootMass=mean(uRootMass))%>% slice(chull(LeafMoisture,uRootMass))-> forGGhull forGG%>% group_by(Site,DaysSincePlanting)%>% summarise(LeafMoisture=mean(LeafMoisture), uRootMass=mean(uRootMass))%>% mutate(label=gsub("Site: ","",Site))-> forGG_sitelabels forGG%>% mutate(plant_label=paste(gsub("Site: ","",Site),":",LETTERS[Individual],sep=""))%>% ggplot(aes(LeafMoisture,uRootMass))+ stat_poly_line() + stat_poly_eq(use_label(c("F","R2","P"),sep="*\"; \"*"),small.r=TRUE,small.p=TRUE)+ geom_convexhull(alpha = 0.3, aes(fill = Site,group=Site))+ geom_point(aes(colour=Site,group=Site))+ geom_text_repel(data=forGG_sitelabels,aes(x=LeafMoisture,y=uRootMass,label=label,colour=Site), min.segment.length = 0, seed = 42, box.padding = 0.5)+ facet_wrap(~DaysSincePlanting,ncol=2)+ xlab("Leaf moisture (%) of parent plant at time of harvesting")+ ylab("Dry root mass (g)")+ theme(legend.position="none")+ scale_y_continuous(expand = c(0, 0), limits = c(-0.05, NA)) ggsave(paste("FinalFiguresV2/Fig_S4.jpg",sep=""),width=7,height=9)