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("tidyr",GroundhogDay) groundhog.library("rstatix",GroundhogDay) groundhog.library("ggpmisc",GroundhogDay) groundhog.library("readr",GroundhogDay) groundhog.library("lubridate",GroundhogDay) setwd("D:\\Google Drive\\0_SpekboomResearchGroup2.0\\3_Experiments\\RegionalTransect21(10)_ParentPlantMaterialExperiment\\manuscript/") read_csv("data_manuscript/chirps_data.csv")-> chirps read_csv("data_manuscript/harvestdata_2023-08-29.csv")-> roots read_csv("data_manuscript/parentplantleafmoisturedata_2023-08-29.csv")-> leaves ################################################################################ # Obtaining the rainfall for various months before the harvest date f <- function(n_months) { chirps%>% as_tibble()%>% mutate(date=ymd(date))%>% filter(date<=ymd("2021-10-13"))%>% filter(date>=ymd("2021-10-13")-months(n_months))%>% group_by(Site)%>% summarise(ppt_sum=sum(chirps))%>% return() } f(1)%>%rename(months_1=ppt_sum)%>% left_join(f(2)%>%rename(months_2=ppt_sum))%>% left_join(f(3)%>%rename(months_3=ppt_sum))%>% left_join(f(6)%>%rename(months_6=ppt_sum))%>% left_join(f(9)%>%rename(months_9=ppt_sum))%>% left_join(f(12)%>%rename(months_12=ppt_sum))%>% round(0)-> chirps_summary ################################################################################ # Obtaining leaf moisture values for each site leaves%>% group_by(Site,Individual)%>% summarise(LeafMoisture=mean(LeafMoisture))%>% group_by(Site)%>% summarise(LeafMoisture=mean(LeafMoisture))-> leaves_summary ################################################################################ # Obtaining root values for each site roots%>% filter(SamplingEvent%in%4:8)%>% group_by(Site,Individual,SamplingEvent)%>% summarise(RootMass=mean(RootMass,na.rm=T))%>% group_by(Site,SamplingEvent)%>% summarise(RootMass=mean(RootMass))%>% mutate(SamplingEvent=paste0("SE_",SamplingEvent))%>% pivot_wider(names_from = SamplingEvent,values_from = RootMass)-> rootmass_summary ################################################################################ left_join(chirps_summary,leaves_summary)%>% left_join(rootmass_summary)-> dat ################################################################################ dat%>% select(-SE_4,-SE_5,-SE_6,-SE_7,-SE_8)%>% pivot_longer(cols=2:7,names_to = "months_n",values_to = "sum_ppt")%>% mutate(months_n=factor(months_n,levels=c("months_1","months_2","months_3","months_6","months_9","months_12"), labels=c("1 month","2 months","3 months","6 months","9 months","12 months")))%>% group_by(months_n)%>% cor_test(vars=LeafMoisture,vars2=sum_ppt) dat%>% pivot_longer(cols=2:7,names_to = "months_n",values_to = "sum_ppt")%>% mutate(months_n=factor(months_n,levels=c("months_1","months_2","months_3","months_6","months_9","months_12"), labels=c("1 month","2 months","3 months","6 months","9 months","12 months")))%>% ggplot(aes(sum_ppt,LeafMoisture))+ geom_smooth(method="lm")+ geom_point(aes(size=SE_7,fill=SE_7),shape=21)+ #geom_point(aes(size=SE_7),shape=1)+ scale_fill_gradient2(low = "red",mid="orange",high="green", )+ geom_text_repel(aes(label=Site))+ facet_wrap(~months_n,scales="free")+ xlab("Sum of precipitation")+ ylab("Mean leaf moisture (%; n=5)")+ guides(size="none")+ labs(fill="Root\nmass\n(g)")+ # stat_poly_eq(aes(label = sprintf("%s*\"; \"*%s", # after_stat(rr.label), # after_stat(p.value.label))), # small.r=TRUE, # small.p=TRUE) stat_poly_eq(use_label(c("F","R2","P"),sep="*\"; \"*"),small.r=TRUE,small.p=TRUE) ggsave("FinalFiguresV2/Fig_S3.jpg",width=10,height=6)