Load R packages

library(ggplot2)
library(ggpubr)
library(lme4)
library(emmeans)
library(lmerTest)
library(Hmisc)
library(ggeffects)
library(MASS)
library(viridis)
library(sp)
library(stringr)

Create function to calculate MRD and D90 from root biomass data

The vrd function calculates the following parameters for each rhizobox:

vrd<-function(x, data, depth, replicate, D=90){
  
  #x is a formula: response~factor
  #data is a data frame with the raw data
  #depth is the name of the column with maxDepth values (character string)
  #replicate is the name of the column with replicate IDs (character string)
  #D is the depth threshold (in %)
  
  if (class(x)=="formula"){
    
    response<-as.character(x[[2]])
    factor<-as.character(x[[3]])}
  
  res<-aggregate(data[,response], by=list(Treatment=data[,factor], Rz=data[,"Rz"], Replicate=data[,replicate]), sum)
  meanRDW<-aggregate(data[,response], by=list(Treatment=data[,factor], Rz=data[,"Rz"], Replicate=data[,replicate]), mean)
  sdRDW<-aggregate(data[,response], by=list(Treatment=data[,factor], Rz=data[,"Rz"], Replicate=data[,replicate]), sd)
  colnames(res)[4]<-"RDWtotal"
  res$MRD<-NA
  res$beta<-NA
  res<-res[order(res$Treatment),]
  
  for (i in 1:nrow(res)){
    
    sub<-data[data[,factor]==res$Treatment[i] & data[,replicate]==res$Replicate[i], c(factor, replicate, depth, response)]
    sub[,factor]<-as.character(sub[,factor])
    sub[nrow(sub)+1,]<-c(sub[1,factor], sub[1,replicate], 0, 0)
    sub[,response]<-as.numeric(sub[,response])
    sub[,depth]<-as.numeric(sub[,depth])
    sub<-sub[order(sub[,depth]),]
    sub[,response]<-cumsum(sub[,response])/sum(sub[,response])
    
    r<-sub[,response]
    d<-sub[,depth]
    
    model<-nls(r~1-beta^d, start=list(beta=1)) #Fit model
    
    res$beta[i]<-coef(model)
    
    res$MRD[i]<-sum((sub[,response]/sum(sub[,response]))*(sub[,depth]-5))}
  
  if (D<100) {res[,paste("D", D, sep="")]<-log(1-(D/100))/log(res$beta)} else {stop("D must be smaller than 100")}
  
  res$invCV<-meanRDW$x/sdRDW$x
  
  return(res[,c(2,1,3:8)])}

Create function to calculate unstandardised effect sizes

bootstrap_ES is an R function calculating unstandardised effect sizes for each treatment and their compatibility intervals (bootstrap resampling using the percentile method) for one response variable. The number of bootstrap resamples is set using n_perm (default to 20000). The argument plot can be used to create a histogram displaying the results.

This function is a modified version of the function coded by Masahiro Ryo for the following paper: Rillig et al (2019). The role of multiple global change factors in driving soil functions and microbial biodiversity. Science, 366, 886-890.

bootstrap_ES <- function(response, data=data, contr, n_perm = 20000, plot=FALSE){
  
  #response is the response variable
  #data is a data frame with the raw data
  #contr is a vector of contrasts (factor level separated by "/", no space)
  
  summary <- data.frame(Contrast=NA, lowCI=NA, ES=NA, highCI=NA, relES=NA)
  alles <- data.frame()
  row<-0
  
    for (c in contr){
      
      split<-strsplit(c, "/")[[1]]
      
      bs <- numeric(0)
      population_1 <- na.omit(data[data$Treatment==split[1], response])
      population_2 <- na.omit(data[data$Treatment==split[2], response])
      size_1 <- length(population_1)
      size_2 <- length(population_2)
      
      if (size_1==0|size_2==0){} else {
        
        row<-row+1
        
        set.seed(123) #For reproducibility
        
        for (i in c(1:n_perm)){
          
          k_1 <- mean(sample(population_1, size_1, replace = T))
          k_2 <- mean(sample(population_2, size_2, replace = T))
          bs <- append(bs, k_1-k_2)}
      
      summary[row,1] <- c
      summary[row,2:4] <- c(quantile(bs, .025), mean(population_1)-mean(population_2), quantile(bs, .975))
      summary[row,5] <- 100*(mean(population_1)-mean(population_2))/mean(population_2)
      alles<-rbind(alles, data.frame(Contrast=rep(c, n_perm), ES=bs))}
  
      if (plot==TRUE){
        hist(bs, main=c, xlab=paste("ES", response, sep=" "))
        points(mean(population_1)-mean(population_2), 0, pch=16, cex=2, col="red")
        segments(x0=quantile(bs, .025), y0=0, x1=quantile(bs, .975), y1=0, lwd=2, col="red")}}
  
  return(list(summary=summary, bootstrap=alles))}

Analysis of shoot biomass data

Load data

shoot <- read.delim("Z:/Poem/Rhizoboxes/0_Rz_experiment_data/Data/Data_shoot_biomass_RZ_PE_2017.txt")
shoot<-as.data.frame(shoot)
shoot$Treatment<-as.factor(shoot$Treatment)

#Convert data in mg
shoot[,4:16]<-shoot[,4:16]*1000

#Remove rhizoboxes where Lotus corniculatus did not grow
shoot<-na.omit(shoot)

#Prepare data for ggplot
shoot1<-data.frame(Treatment=rep(shoot$Treatment, 9),
                   Replicate=rep(shoot$Replicate, 9),
                   Species=rep(c("Trifolium pratense", "Lotus corniculatus", "Medicago sativa", "Festuca rubra", "Holcus lanatus", "Dactylis glomerata", "Centaurea jacea", "Leucanthemum vulgare", "Achillea millefolium"), each=31),
                   SDW=as.vector(as.matrix(shoot[,4:12])))

Plot shoot biomass for each species

shoot1$Treatment<-factor(shoot1$Treatment, levels=c("Sync1", "F-first", "G-first", "L-first", "Sync2"))
shoot1$Species<-factor(shoot1$Species, levels=c("Achillea millefolium", "Centaurea jacea", "Leucanthemum vulgare", "Dactylis glomerata", "Festuca rubra", "Holcus lanatus", "Lotus corniculatus", "Medicago sativa","Trifolium pratense"))
                                                
colors<-c("#999999", "#56B4E9", "#E69F00", "#009E73", "black")

(p1<-ggplot(shoot1, aes(x=Treatment, y=SDW, color=Treatment))+
      facet_wrap(~Species, scales="free_y")+
      geom_jitter(shape=1, width=0.15)+
      stat_summary(fun.data="mean_cl_boot", size=0.5)+
      theme_bw()+
      theme(legend.position = "none")+
      ylab("Shoot dry weight (mg)")+
      xlab("")+
      theme(axis.text=element_text(size=10, color="black"),
            strip.text=element_text(face="italic", size=10),
            axis.title.y=element_text(margin=margin(r=10)),
            axis.text.x = element_text(angle=90, vjust=0.5))+
      scale_color_manual(values=colors))

#ggsave("Figure3.tiff", p1, dpi=1000, compression="lzw", width=18, height=17, units="cm")

Plot total shoot biomass

shoot$Treatment<-factor(shoot$Treatment, levels=c("Sync1", "F-first", "G-first", "L-first", "Sync2"))
colors<-c("#999999", "#56B4E9", "#E69F00", "#009E73", "black")

(p2<-ggplot(shoot, aes(x=Treatment, y=Total, color=Treatment)) + 
    geom_jitter(shape=1, width=0.15) + 
    labs(x = "", y = "Total shoot dry weight (mg)") +
    theme_bw()+
    stat_summary(fun.data="mean_cl_boot", size=0.5)+
    scale_color_manual(values=colors)+
    theme(legend.position = "none",
          axis.text=element_text(size=10, color="black"),
          axis.title.y = element_text(margin=margin(t=0,b=0,r=10,l=0)),
          axis.text.x=element_text(angle=0)))

#ggsave("Total_shoot_productivity.tiff", p2, dpi=1000, compression="lzw", width=9, height=9, units="cm")

Effect sizes

Achillea millefolium

es.Am<-bootstrap_ES(response="Am", data=shoot, contr=c("F-first/Sync1", "G-first/Sync2", "L-first/Sync2", "G-first/L-first"), plot=FALSE)
knitr::kable(es.Am$summary)
Contrast lowCI ES highCI relES
F-first/Sync1 11.578810 52.5740476 96.240958 86.735407
G-first/Sync2 -5.447157 -0.7791429 4.181443 -7.411937
L-first/Sync2 -6.920675 -2.4103333 2.208533 -22.929351
G-first/L-first -1.845958 1.6311905 5.501940 20.134011
ggplot(es.Am$bootstrap)+
  geom_hline(yintercept = 0)+
  stat_ydensity(aes(x=Contrast, y=ES), fill="grey50", color=adjustcolor("white", alpha.f = 0.1), alpha=0.3)+
  geom_segment(data=es.Am$summary, aes(x=Contrast, xend=Contrast, y=lowCI, yend=highCI), color="black", size=0.5)+
  geom_point(data=es.Am$summary, aes(x=Contrast, y=ES), shape=16, color="black")+
  theme_bw()+
  xlab("")+
  ylab("ES SDW (mg)")+
  theme(axis.title=element_text(color="black", face="plain"),
  axis.title.y=element_text(margin = margin(t = 0, r = 5, b = 0, l = 0)),
  axis.title.x=element_blank(),
  axis.text=element_text(color="black"))

Centaurea jacea

es.Cj<-bootstrap_ES(response="Cj", data=shoot, contr=c("F-first/Sync1", "G-first/Sync2", "L-first/Sync2", "G-first/L-first"), plot=FALSE)
knitr::kable(es.Cj$summary)
Contrast lowCI ES highCI relES
F-first/Sync1 36.250238 71.274048 107.19702 67.04089
G-first/Sync2 -84.578643 -25.935714 10.88806 -52.59727
L-first/Sync2 -89.128725 -30.936667 5.44140 -62.73913
G-first/L-first -5.397494 5.000952 15.77407 27.21854
ggplot(es.Cj$bootstrap)+
  geom_hline(yintercept = 0)+
  stat_ydensity(aes(x=Contrast, y=ES), fill="grey50", color=adjustcolor("white", alpha.f = 0.1), alpha=0.3)+
  geom_segment(data=es.Cj$summary, aes(x=Contrast, xend=Contrast, y=lowCI, yend=highCI), color="black", size=0.5)+
  geom_point(data=es.Cj$summary, aes(x=Contrast, y=ES), shape=16, color="black")+
  theme_bw()+
  xlab("")+
  ylab("ES SDW (mg)")+
  theme(axis.title=element_text(color="black", face="plain"),
  axis.title.y=element_text(margin = margin(t = 0, r = 5, b = 0, l = 0)),
  axis.title.x=element_blank(),
  axis.text=element_text(color="black"))

Leucanthemum vulgare

es.Lv<-bootstrap_ES(response="Lv", data=shoot, contr=c("F-first/Sync1", "G-first/Sync2", "L-first/Sync2", "G-first/L-first"), plot=FALSE)
knitr::kable(es.Lv$summary)
Contrast lowCI ES highCI relES
F-first/Sync1 -19.749756 9.319762 39.939059 10.02679
G-first/Sync2 -12.231507 -2.668857 8.053436 -12.88307
L-first/Sync2 -13.625283 -5.392667 4.629875 -26.03141
G-first/L-first -3.178429 2.723810 8.423833 17.77557
ggplot(es.Lv$bootstrap)+
  geom_hline(yintercept = 0)+
  stat_ydensity(aes(x=Contrast, y=ES), fill="grey50", color=adjustcolor("white", alpha.f = 0.1), alpha=0.3)+
  geom_segment(data=es.Lv$summary, aes(x=Contrast, xend=Contrast, y=lowCI, yend=highCI), color="black", size=0.5)+
  geom_point(data=es.Lv$summary, aes(x=Contrast, y=ES), shape=16, color="black")+
  theme_bw()+
  xlab("")+
  ylab("ES SDW (mg)")+
  theme(axis.title=element_text(color="black", face="plain"),
  axis.title.y=element_text(margin = margin(t = 0, r = 5, b = 0, l = 0)),
  axis.title.x=element_blank(),
  axis.text=element_text(color="black"))

Dactylis glomerata

es.Dg<-bootstrap_ES(response="Dg", data=shoot, contr=c("G-first/Sync1", "F-first/Sync2", "L-first/Sync2", "F-first/L-first"), plot=FALSE)
knitr::kable(es.Dg$summary)
Contrast lowCI ES highCI relES
G-first/Sync1 -45.913107 -13.5771429 19.557750 -9.023499
F-first/Sync2 -8.823333 -3.1780000 2.711850 -10.636589
L-first/Sync2 -12.002817 -3.6263333 4.021200 -12.137135
F-first/L-first -6.698333 0.4483333 8.290042 1.707828
ggplot(es.Dg$bootstrap)+
  geom_hline(yintercept = 0)+
  stat_ydensity(aes(x=Contrast, y=ES), fill="grey50", color=adjustcolor("white", alpha.f = 0.1), alpha=0.3)+
  geom_segment(data=es.Dg$summary, aes(x=Contrast, xend=Contrast, y=lowCI, yend=highCI), color="black", size=0.5)+
  geom_point(data=es.Dg$summary, aes(x=Contrast, y=ES), shape=16, color="black")+
  theme_bw()+
  xlab("")+
  ylab("ES SDW (mg)")+
  theme(axis.title=element_text(color="black", face="plain"),
  axis.title.y=element_text(margin = margin(t = 0, r = 5, b = 0, l = 0)),
  axis.title.x=element_blank(),
  axis.text=element_text(color="black"))

Festuca rubra

es.Fr<-bootstrap_ES(response="Fr", data=shoot, contr=c("G-first/Sync1", "F-first/Sync2", "L-first/Sync2", "F-first/L-first"), plot=FALSE)
knitr::kable(es.Fr$summary)
Contrast lowCI ES highCI relES
G-first/Sync1 -7.820036 0.4571429 9.655821 1.148971
F-first/Sync2 -4.303050 1.0393333 6.057667 17.784622
L-first/Sync2 -4.414333 0.2893333 4.712667 4.950947
F-first/L-first -2.473333 0.7500000 3.750042 12.228261
ggplot(es.Fr$bootstrap)+
  geom_hline(yintercept = 0)+
  stat_ydensity(aes(x=Contrast, y=ES), fill="grey50", color=adjustcolor("white", alpha.f = 0.1), alpha=0.3)+
  geom_segment(data=es.Fr$summary, aes(x=Contrast, xend=Contrast, y=lowCI, yend=highCI), color="black", size=0.5)+
  geom_point(data=es.Fr$summary, aes(x=Contrast, y=ES), shape=16, color="black")+
  theme_bw()+
  xlab("")+
  ylab("ES SDW (mg)")+
  theme(axis.title=element_text(color="black", face="plain"),
  axis.title.y=element_text(margin = margin(t = 0, r = 5, b = 0, l = 0)),
  axis.title.x=element_blank(),
  axis.text=element_text(color="black"))

Holcus lanatus

es.Hl<-bootstrap_ES(response="Hl", data=shoot, contr=c("G-first/Sync1", "F-first/Sync2", "L-first/Sync2", "F-first/L-first"), plot=FALSE)
knitr::kable(es.Hl$summary)
Contrast lowCI ES highCI relES
G-first/Sync1 -38.271750 8.782857 59.175857 6.388329
F-first/Sync2 -11.636375 -4.155000 3.415075 -29.055944
L-first/Sync2 -10.111333 -4.400000 1.321333 -30.769231
F-first/L-first -6.998458 0.245000 7.488500 2.474747
ggplot(es.Hl$bootstrap)+
  geom_hline(yintercept = 0)+
  stat_ydensity(aes(x=Contrast, y=ES), fill="grey50", color=adjustcolor("white", alpha.f = 0.1), alpha=0.3)+
  geom_segment(data=es.Hl$summary, aes(x=Contrast, xend=Contrast, y=lowCI, yend=highCI), color="black", size=0.5)+
  geom_point(data=es.Hl$summary, aes(x=Contrast, y=ES), shape=16, color="black")+
  theme_bw()+
  xlab("")+
  ylab("ES SDW (mg)")+
  theme(axis.title=element_text(color="black", face="plain"),
  axis.title.y=element_text(margin = margin(t = 0, r = 5, b = 0, l = 0)),
  axis.title.x=element_blank(),
  axis.text=element_text(color="black"))

Lotus corniculatus

es.Lc<-bootstrap_ES(response="Lc", data=shoot, contr=c("L-first/Sync1", "F-first/Sync2", "G-first/Sync2", "F-first/G-first"), plot=FALSE)
knitr::kable(es.Lc$summary)
Contrast lowCI ES highCI relES
L-first/Sync1 -18.346214 -0.5166667 18.913381 -1.222590
F-first/Sync2 -7.979017 -2.5560000 2.419575 -21.096071
G-first/Sync2 -6.556586 -0.8860000 4.738357 -7.312644
F-first/G-first -6.781667 -1.6700000 3.104065 -14.870882
ggplot(es.Lc$bootstrap)+
  geom_hline(yintercept = 0)+
  stat_ydensity(aes(x=Contrast, y=ES), fill="grey50", color=adjustcolor("white", alpha.f = 0.1), alpha=0.3)+
  geom_segment(data=es.Lc$summary, aes(x=Contrast, xend=Contrast, y=lowCI, yend=highCI), color="black", size=0.5)+
  geom_point(data=es.Lc$summary, aes(x=Contrast, y=ES), shape=16, color="black")+
  theme_bw()+
  xlab("")+
  ylab("ES SDW (mg)")+
  theme(axis.title=element_text(color="black", face="plain"),
  axis.title.y=element_text(margin = margin(t = 0, r = 5, b = 0, l = 0)),
  axis.title.x=element_blank(),
  axis.text=element_text(color="black"))

Medicago sativa

es.Ms<-bootstrap_ES(response="Ms", data=shoot, contr=c("L-first/Sync1", "F-first/Sync2", "G-first/Sync2", "F-first/G-first"), plot=FALSE)
knitr::kable(es.Ms$summary)
Contrast lowCI ES highCI relES
L-first/Sync1 -115.36010 -23.928809 64.976494 -10.038215
F-first/Sync2 -25.36776 -6.472667 12.394667 -8.660708
G-first/Sync2 -30.61861 -10.498857 9.192579 -14.047925
F-first/G-first -19.09219 4.026191 27.406917 6.267699
ggplot(es.Ms$bootstrap)+
  geom_hline(yintercept = 0)+
  stat_ydensity(aes(x=Contrast, y=ES), fill="grey50", color=adjustcolor("white", alpha.f = 0.1), alpha=0.3)+
  geom_segment(data=es.Ms$summary, aes(x=Contrast, xend=Contrast, y=lowCI, yend=highCI), color="black", size=0.5)+
  geom_point(data=es.Ms$summary, aes(x=Contrast, y=ES), shape=16, color="black")+
  theme_bw()+
  xlab("")+
  ylab("ES SDW (mg)")+
  theme(axis.title=element_text(color="black", face="plain"),
  axis.title.y=element_text(margin = margin(t = 0, r = 5, b = 0, l = 0)),
  axis.title.x=element_blank(),
  axis.text=element_text(color="black"))

Trifolium pratense

es.Tp<-bootstrap_ES(response="Tp", data=shoot, contr=c("L-first/Sync1", "F-first/Sync2", "G-first/Sync2", "G-first/F-first"), plot=FALSE)
knitr::kable(es.Tp$summary)
Contrast lowCI ES highCI relES
L-first/Sync1 -2.413631 22.454286 47.3319464 21.47796
F-first/Sync2 -17.259392 -5.202667 7.0843333 -13.25318
G-first/Sync2 -24.240300 -13.258857 -1.8465929 -33.77536
G-first/F-first -15.747232 -8.056190 -0.1942738 -23.65757
ggplot(es.Tp$bootstrap)+
  geom_hline(yintercept = 0)+
  stat_ydensity(aes(x=Contrast, y=ES), fill="grey50", color=adjustcolor("white", alpha.f = 0.1), alpha=0.3)+
  geom_segment(data=es.Tp$summary, aes(x=Contrast, xend=Contrast, y=lowCI, yend=highCI), color="black", size=0.5)+
  geom_point(data=es.Tp$summary, aes(x=Contrast, y=ES), shape=16, color="black")+
  theme_bw()+
  xlab("")+
  ylab("ES SDW (mg)")+
  theme(axis.title=element_text(color="black", face="plain"),
  axis.title.y=element_text(margin = margin(t = 0, r = 5, b = 0, l = 0)),
  axis.title.x=element_blank(),
  axis.text=element_text(color="black"))

Total shoot biomass

es.Total<-bootstrap_ES(response="Total", data=shoot, contr=c("F-first/G-first", "F-first/L-first", "G-first/L-first"), plot=FALSE)
knitr::kable(es.Total$summary)
Contrast lowCI ES highCI relES
F-first/G-first -16.771786 72.634286 151.1488 15.258800
F-first/L-first -2.015292 81.375000 169.0913 17.414799
G-first/L-first -83.829524 8.740714 111.8048 1.870572
ggplot(es.Total$bootstrap)+
  geom_hline(yintercept = 0)+
  stat_ydensity(aes(x=Contrast, y=ES), fill="grey50", color=adjustcolor("white", alpha.f = 0.1), alpha=0.3)+
  geom_segment(data=es.Total$summary, aes(x=Contrast, xend=Contrast, y=lowCI, yend=highCI), color="black", size=0.5)+
  geom_point(data=es.Total$summary, aes(x=Contrast, y=ES), shape=16, color="black")+
  theme_bw()+
  xlab("")+
  ylab("ES SDW (mg)")+
  theme(axis.title=element_text(color="black", face="plain"),
  axis.title.y=element_text(margin = margin(t = 0, r = 5, b = 0, l = 0)),
  axis.title.x=element_blank(),
  axis.text=element_text(color="black"))

Analysis of root biomass data

Load root biomass data

root <- read.delim("Z:/Poem/Rhizoboxes/0_Rz_experiment_data/Data/Data_root_biomass_RZ_PE_2017.txt")
root<-as.data.frame(root)
root$Treatment<-as.factor(root$Treatment)

root$RDW<-root$RDW*1000 #Convert to mg
root<-root[-which(root$Rz==137),] #Root biomass in layer 5 much greater than in layers 4 and 3 (this might be due to a data encoding mistake)

Plot total root productivity

root$Treatment<-factor(root$Treatment, levels=c("Sync1", "F-first", "G-first", "L-first", "Sync2"))
colors<-c("#999999", "#56B4E9", "#E69F00", "#009E73", "black")

root1<-vrd(x=RDW~Treatment, data=root, depth="maxDepth", replicate="Replicate", D=90)

(p3<-ggplot(root1, aes(x=Treatment, y=RDWtotal, color=Treatment)) + 
      geom_jitter(shape=1, width=0.1) + 
      labs(x = "", y = "Total root dry weight (mg)") +
      theme_bw()+
      stat_summary(fun.data="mean_cl_boot", size=0.5)+
      scale_color_manual(values=colors)+
      theme(legend.position = "none",
            axis.text=element_text(size=10, color="black"),
            axis.title.y = element_text(margin=margin(t=0,b=0,r=10,l=0)),
            axis.text.x=element_text(angle=0))+
      scale_y_continuous(limits=c(0,300), breaks=c(0,50,100,150,200,250,300)))

(p<-ggplot(root1, aes(x=Treatment, y=invCV, color=Treatment)) + 
      geom_jitter(shape=1, width=0.1) + 
      labs(x = "", y = "Community inverse CV") +
      theme_bw()+
      stat_summary(fun.data="mean_cl_boot", size=0.5)+
      scale_color_manual(values=colors)+
      theme(legend.position = "none",
            axis.text=element_text(size=10, color="black"),
            axis.title.y = element_text(margin=margin(t=0,b=0,r=10,l=0)),
            axis.text.x=element_text(angle=0)))

#ggsave("Total_root_productivity.tiff", p3, dpi=1000, compression="lzw", width=9, height=9, units="cm")

Effect sizes

Total root productivity

es.rdw<-bootstrap_ES(response="RDWtotal", data=root1, contr=c("F-first/G-first", "F-first/L-first", "G-first/L-first"), plot=FALSE)
knitr::kable(es.rdw$summary)
Contrast lowCI ES highCI relES
F-first/G-first -31.02810 -2.052667 24.24370 -1.9604347
F-first/L-first -27.62605 -0.832650 24.72523 -0.8046121
G-first/L-first -28.74063 1.220017 32.09020 1.1789349
ggplot(es.rdw$bootstrap)+
  geom_hline(yintercept = 0)+
  stat_ydensity(aes(x=Contrast, y=ES), fill="grey50", color=adjustcolor("white", alpha.f = 0.1), alpha=0.3)+
  geom_segment(data=es.rdw$summary, aes(x=Contrast, xend=Contrast, y=lowCI, yend=highCI), color="black", size=0.5)+
  geom_point(data=es.rdw$summary, aes(x=Contrast, y=ES), shape=16, color="black")+
  theme_bw()+
  xlab("")+
  ylab("ES RDW (mg)")+
  theme(axis.title=element_text(color="black", face="plain"),
  axis.title.y=element_text(margin = margin(t = 0, r = 5, b = 0, l = 0)),
  axis.title.x=element_blank(),
  axis.text=element_text(color="black"))

MRD biomass

es.mrdb<-bootstrap_ES(response="MRD", data=root1, contr=c("F-first/G-first", "F-first/L-first", "G-first/L-first"), plot=FALSE)
knitr::kable(es.mrdb$summary)
Contrast lowCI ES highCI relES
F-first/G-first 0.1718820 0.3980583 0.6330516 1.2652580
F-first/L-first -0.2695726 0.0896462 0.4362503 0.2821809
G-first/L-first -0.6664817 -0.3084121 0.0230946 -0.9707941
ggplot(es.mrdb$bootstrap)+
  geom_hline(yintercept = 0)+
  stat_ydensity(aes(x=Contrast, y=ES), fill="grey50", color=adjustcolor("white", alpha.f = 0.1), alpha=0.3)+
  geom_segment(data=es.mrdb$summary, aes(x=Contrast, xend=Contrast, y=lowCI, yend=highCI), color="black", size=0.5)+
  geom_point(data=es.mrdb$summary, aes(x=Contrast, y=ES), shape=16, color="black")+
  theme_bw()+
  xlab("")+
  ylab("ES MRD (cm)")+
  theme(axis.title=element_text(color="black", face="plain"),
  axis.title.y=element_text(margin = margin(t = 0, r = 5, b = 0, l = 0)),
  axis.title.x=element_blank(),
  axis.text=element_text(color="black"))

Create combined plot for aboveground and belowground productivity (figure 2)

(figure2<-ggarrange(p2, p3, align="hv", nrow=1, ncol=2, labels=c("(a)", "(b)"), font.label=list(size=12)))

#ggsave("Figure2.tiff", figure2, dpi=1000, compression="lzw", width=18, height=9, units="cm")

Plot root biomass distribution in soil layers

supp.labs<-c("0-10 cm", "10-20 cm", "20-30 cm", "30-40 cm", "40-50 cm", ">50 cm")
names(supp.labs)<-c("0-10 cm", "10-20 cm", "20-30 cm", "30-40 cm", "40-50 cm", "50-60 cm")
  
(p4<-ggplot(root, aes(x=Treatment, y=RDW, color=Treatment)) + 
    geom_jitter(shape=1, width=0.1) + 
    labs(x = "", y = "Total root dry weight (mg)") +
    theme_bw()+
    stat_summary(fun.data="mean_cl_boot", size=0.5)+
    scale_color_manual(values=colors)+
    theme(legend.position = "none",
          axis.text=element_text(color="black"),
          axis.title.y = element_text(margin=margin(t=0,b=0,r=10,l=0)),
          axis.text.x=element_text(size=10, angle=90),
          axis.text.y=element_text(size=10),
          strip.text = element_text(size=10))+
    facet_wrap(~Layer, scales="free_y",
               labeller=labeller(Layer=supp.labs)))

#ggsave("Vertical_root_distribution.tiff", p4, dpi=1000, compression="lzw", width=18, height=13, units="cm")

Root biomass distribution in the soil

Because some layers did not contain any roots (RDW=0), we had zero-inflated continuous data (\(Y \ge 0\)). Data were analysed using a hurdle model combining a gamma GLMM and a Bernoulli GLMM (zero-altered gamma model or ZAG model). In a ZAG model, zeroes are generated by the binary part of the model (1 or 0). Non-zero data (that occur that roots are present in a layer) are modeled using a second (continuous) distribution (gamma in this case). The hurdle model was fitted according to Chapter 7 in Zuur and Ieno (2016) Beginner’s guide to zero-inflated models with R. Highland Statistics Ltd. 

Fit gamma component of hurdle model

root$Depth<-root$maxDepth-5

root.pos<-subset(root, RDW>0) #Only select positive RDW values
root.pos$Rz<-factor(root.pos$Rz)

#Fit GLMM with gamma distribution
H1<-glmmPQL(fixed=RDW~Depth*Treatment, random=~1|Rz, data=root.pos, family=Gamma(link="log"))
summary(H1)
## Linear mixed-effects model fit by maximum likelihood
##   Data: root.pos 
##   AIC BIC logLik
##    NA  NA     NA
## 
## Random effects:
##  Formula: ~1 | Rz
##         (Intercept)  Residual
## StdDev:   0.2093552 0.4739855
## 
## Variance function:
##  Structure: fixed weights
##  Formula: ~invwt 
## Fixed effects:  RDW ~ Depth * Treatment 
##                            Value  Std.Error  DF    t-value p-value
## (Intercept)             5.198650 0.17303757 129  30.043473  0.0000
## Depth                  -0.081493 0.00441935 129 -18.440053  0.0000
## TreatmentF-first       -0.882303 0.25577033  25  -3.449592  0.0020
## TreatmentG-first       -0.158325 0.27088042  25  -0.584484  0.5641
## TreatmentL-first       -1.024877 0.25470441  25  -4.023791  0.0005
## TreatmentSync2         -1.357011 0.27549528  25  -4.925712  0.0000
## Depth:TreatmentF-first -0.001688 0.00662837 129  -0.254618  0.7994
## Depth:TreatmentG-first -0.058010 0.00846542 129  -6.852566  0.0000
## Depth:TreatmentL-first  0.007769 0.00650511 129   1.194263  0.2346
## Depth:TreatmentSync2   -0.020982 0.00789831 129  -2.656462  0.0089
##  Correlation: 
##                        (Intr) Depth  TrtmF- TrtmG- TrtmL- TrtmS2 Dp:TF- Dp:TG-
## Depth                  -0.766                                                 
## TreatmentF-first       -0.677  0.518                                          
## TreatmentG-first       -0.639  0.489  0.432                                   
## TreatmentL-first       -0.679  0.521  0.460  0.434                            
## TreatmentSync2         -0.628  0.481  0.425  0.401  0.427                     
## Depth:TreatmentF-first  0.511 -0.667 -0.766 -0.326 -0.347 -0.321              
## Depth:TreatmentG-first  0.400 -0.522 -0.271 -0.770 -0.272 -0.251  0.348       
## Depth:TreatmentL-first  0.521 -0.679 -0.352 -0.333 -0.766 -0.327  0.453  0.355
## Depth:TreatmentSync2    0.429 -0.560 -0.290 -0.274 -0.291 -0.758  0.373  0.292
##                        Dp:TL-
## Depth                        
## TreatmentF-first             
## TreatmentG-first             
## TreatmentL-first             
## TreatmentSync2               
## Depth:TreatmentF-first       
## Depth:TreatmentG-first       
## Depth:TreatmentL-first       
## Depth:TreatmentSync2    0.380
## 
## Standardized Within-Group Residuals:
##         Min          Q1         Med          Q3         Max 
## -1.66689033 -0.75461721 -0.09996008  0.55289496  3.64472676 
## 
## Number of Observations: 164
## Number of Groups: 30
#Model validation
E1<-resid(H1, type="pearson")
F1<-fitted(H1, type="response")
plot(F1, E1, xlab="Fitted values", ylab="Residuals"); abline(h=0)

boxplot(E1~root.pos$Treatment, xlab="", ylab="Residuals")

boxplot(E1~root.pos$Depth, xlab="Depth (cm)", ylab="Residuals")

#Make predictions
pred.mm <- data.frame(Depth=rep(seq(5,55,by=0.1), 5), Treatment=rep(unique(root$Treatment), each=501))
pred.mm$Pred <- predict(H1, newdata=pred.mm, type="response", level=0)

#Plot GLMM fit
(p5<-ggplot(pred.mm) +
    geom_jitter(data=root.pos, aes(x=Depth, y=RDW, colour=Treatment), width=1, shape=1) +
    geom_line(aes(x = Depth, y = Pred, color=Treatment), size=1) +
    ylab("Root dry weight (mg)")+
    xlab("Depth (cm)")+ 
    theme_bw()+
    theme(legend.title=element_blank(),
          axis.text=element_text(size=10, color="black"),
          axis.title.y = element_text(margin=margin(r=10)),
          axis.title.x = element_text(margin=margin(t=10)))+
    scale_color_manual(values=colors))

#Plot GLMM fit
#One curve for each rhizobox
(p6<-ggplot(root.pos) +
    geom_jitter(aes(x=Depth, y=RDW, colour=Treatment), width=1, shape=1) +
    geom_line(data=cbind(root.pos, Pred=predict(H1, type="response")), aes(x = Depth, y = Pred, color=Treatment, group=Rz), size=1) +
    ylab("Root dry weight (mg)")+
    xlab("Depth (cm)")+ 
    theme_bw()+
    theme(legend.title=element_blank(),
          axis.text=element_text(size=10, color="black"),
          axis.title.y = element_text(margin=margin(r=10)),
          axis.title.x = element_text(margin=margin(t=10)))+
    scale_color_manual(values=colors))

Fit binomial component of hurdle model

root$RDW.01<-as.numeric(root$RDW > 0)
root$Rz<-factor(root$Rz)
root$sDepth<-scale(root$Depth, center=TRUE, scale=TRUE)

#Fit GLMM with a binomial distribution
H2<-glmmPQL(fixed=RDW.01~Depth*Treatment, random=~1|Rz, data=root, family=binomial(link="logit"))
summary(H2)
## Linear mixed-effects model fit by maximum likelihood
##   Data: root 
##   AIC BIC logLik
##    NA  NA     NA
## 
## Random effects:
##  Formula: ~1 | Rz
##         (Intercept)    Residual
## StdDev:    13.93088 4.11976e-06
## 
## Variance function:
##  Structure: fixed weights
##  Formula: ~invwt 
## Fixed effects:  RDW.01 ~ Depth * Treatment 
##                            Value Std.Error  DF    t-value p-value
## (Intercept)             32.56637  88.89578 145  0.3663433  0.7146
## Depth                    0.00000   2.57037 145 -0.0000008  1.0000
## TreatmentF-first       171.22284  89.10695  25  1.9215431  0.0661
## TreatmentG-first       144.23931  89.31717  25  1.6149113  0.1189
## TreatmentL-first         0.00000 130.85104  25  0.0000000  1.0000
## TreatmentSync2          50.56918  89.12663  25  0.5673857  0.5755
## Depth:TreatmentF-first  -3.56375   2.57058 145 -1.3863592  0.1678
## Depth:TreatmentG-first  -3.92901   2.57429 145 -1.5262506  0.1291
## Depth:TreatmentL-first   0.00000   3.78348 145  0.0000000  1.0000
## Depth:TreatmentSync2    -1.72216   2.57037 145 -0.6700049  0.5039
##  Correlation: 
##                        (Intr) Depth  TrtmF- TrtmG- TrtmL- TrtmS2 Dp:TF- Dp:TG-
## Depth                  -0.867                                                 
## TreatmentF-first       -0.998  0.865                                          
## TreatmentG-first       -0.995  0.863  0.993                                   
## TreatmentL-first       -0.679  0.589  0.678  0.676                            
## TreatmentSync2         -0.997  0.865  0.995  0.993  0.678                     
## Depth:TreatmentF-first  0.867 -1.000 -0.866 -0.863 -0.589 -0.865              
## Depth:TreatmentG-first  0.866 -0.998 -0.864 -0.866 -0.588 -0.864  0.998       
## Depth:TreatmentL-first  0.589 -0.679 -0.588 -0.587 -0.867 -0.588  0.679  0.678
## Depth:TreatmentSync2    0.867 -1.000 -0.865 -0.863 -0.589 -0.865  1.000  0.998
##                        Dp:TL-
## Depth                        
## TreatmentF-first             
## TreatmentG-first             
## TreatmentL-first             
## TreatmentSync2               
## Depth:TreatmentF-first       
## Depth:TreatmentG-first       
## Depth:TreatmentL-first       
## Depth:TreatmentSync2    0.679
## 
## Standardized Within-Group Residuals:
##           Min            Q1           Med            Q3           Max 
## -5.660781e+00 -1.447565e-02 -6.094571e-13  2.467230e-15  5.230954e+00 
## 
## Number of Observations: 180
## Number of Groups: 30
#Make predictions
pred.mm <- data.frame(Depth=rep(seq(5,55,by=0.1), 5),
                      Treatment=rep(unique(root$Treatment), each=501))
pred.mm$Pred <- predict(H2, newdata=pred.mm, type="response", level=0)

#Plot GLMM fit
(p7<-ggplot(pred.mm) +
    geom_jitter(data=root, aes(x=Depth, y=RDW.01, colour=Treatment), height=0.2, width=1, shape=1) +
    geom_line(aes(x = Depth, y = Pred, color=Treatment), size=1) +
    ylab("Probability that roots are present")+
    xlab("Depth (cm)")+ 
    theme_bw()+
    theme(legend.title=element_blank(),
          axis.text=element_text(size=10, color="black"),
          axis.title.y = element_text(margin=margin(r=10)),
          axis.title.x = element_text(margin=margin(t=10)))+
    scale_color_manual(values=colors))

Merge gamma and binomial components

beta<-fixef(H1) #Extract regression coefficients of Gamma GLMM
gamma<-fixef(H2) #Extract regression coefficients of Binomial GLMM

#Create new data for predictions
newdata <- expand.grid(Depth = seq(5, 55, by = 0.1),
                       Treatment = levels(root$Treatment))

X<-model.matrix(~Depth*Treatment, data=newdata)

mu <- exp(X %*% beta)
Pi  <- exp(X %*% gamma) / (1 + exp(X %*% gamma))

#Get predictions for Hurdle model
newdata$PredZAG<-Pi * mu

#Plot hurdle model fit
(p8<-ggplot(root) +
    geom_jitter(data=root, aes(x=Depth, y=RDW, colour=Treatment), width=1, shape=1) +
    geom_line(data=newdata, aes(x = Depth, y = PredZAG, color=Treatment), size=0.8) +
    ylab("Root dry weight (mg)")+
    xlab("Depth (cm)")+ 
    theme_bw()+
    theme(legend.title=element_blank(),
          legend.position=c(0.85,0.75),
          legend.text=element_text(size=8),
          axis.text=element_text(size=10, color="black"),
          axis.title.y = element_text(margin=margin(r=10)),
          axis.title.x = element_text(margin=margin(t=10)))+
    scale_color_manual(values=colors))

#ggsave("Figure4.tiff", p8, dpi=1000, compression="lzw", width=10, height=9.5, units="cm")

Analysis of root distribution over time

Load RootPainter data

root.depth <- read.csv("Z:/Poem/Rhizoboxes/Backup_RootPainter/drive_rp_sync/projects/PE_rhizotrons_2017_1/results/segmentations/results.csv")

ID <- read.delim("Z:/Poem/Rhizoboxes/0_Rz_experiment_data/Data/Image_RZ.txt")
TIME <- read.delim("Z:/Poem/Rhizoboxes/0_Rz_experiment_data/Data/Date_TimePoint.txt")

filenames<-sapply(str_split(as.character(root.depth$image), pattern="-"), function(x){return(x[5])})
filenames<-as.numeric(sapply(str_split(filenames, pattern="\\."), function(x){return(x[1])}))

root.depth$Date<-sapply(str_split(as.character(root.depth$image), pattern="-"), function(x){
  return(paste(x[1], x[2], x[3], sep="-"))})

root.depth$imageID<-filenames
root.depth$Rz<-ID$RZ[match(filenames, ID$Image)]
root.depth$Time<-TIME$Day[match(root.depth$Date, TIME$Date)]

root.depth<-root.depth[order(root.depth$Rz, root.depth$Time),]

#Add treatment column
root.depth$Treatment<-root1$Treatment[match(root.depth$Rz, root1$Rz)]

#Set Sync2 to zero before the second sowing
root.depth$mrd[which(root.depth$Treatment=="Sync2" & root.depth$Time<=9)]<-0

#Remove rhizoboxes 35, 70, 15, 27, 137
root.depth<-root.depth[-which(root.depth$Rz==35|root.depth$Rz==70|root.depth$Rz==15|root.depth$Rz==27|root.depth$Rz==137),]

root.depth$Treatment<-factor(root.depth$Treatment, levels=c("Sync1", "F-first", "G-first", "L-first", "Sync2"))

Plot mean rooting depth over time

#Create empty dataset for summary statistics
stat.mrd<-data.frame(Treatment=rep(NA, length(unique(root.depth$Rz))),
                     Time=rep(NA, length(unique(root.depth$Rz))),
                     meanValue=rep(NA, length(unique(root.depth$Rz))),
                     lower=rep(NA, length(unique(root.depth$Rz))),
                     upper=rep(NA, length(unique(root.depth$Rz))))
 
k<-0
 
for (i in unique(root.depth$Treatment)){
   
  for (j in unique(root.depth$Time)){
     
    k<-k+1
    sub<-root.depth[root.depth$Treatment==i & root.depth$Time==j,]
    #Calculate compatibility interval (bootstrap resampling)
    set.seed(1)
    a<-smean.cl.boot(sub$mrd, B=10000)
    stat.mrd[k,]<-c(i, j, as.numeric(a))}}
 
stat.mrd[,2]<-as.numeric(stat.mrd[,2])
stat.mrd[,3]<-as.numeric(stat.mrd[,3])
stat.mrd[,4]<-as.numeric(stat.mrd[,4])
stat.mrd[,5]<-as.numeric(stat.mrd[,5])
 
stat.mrd$Treatment<-factor(stat.mrd$Treatment, levels=c("Sync1", "F-first", "G-first", "L-first", "Sync2"))

#Plot mean rooting depth over time
(p9<-ggplot(stat.mrd, aes(x=Time, y=meanValue, color=Treatment))+
  geom_ribbon(aes(ymin=lower, ymax=upper, fill=Treatment, alpha=Treatment), color=NA)+
  geom_line()+
  geom_point(shape=16)+
  geom_vline(xintercept=10, linetype=3)+
  theme_bw()+
  theme(legend.title=element_blank(),
        axis.text=element_text(size=10, color="black"),
        axis.title.y = element_text(margin=margin(r=10)),
        axis.title.x = element_text(margin=margin(t=10)))+
  ylab("MRD (cm)")+
  xlab("Time (days)")+
  scale_color_manual(values=colors)+
  scale_fill_manual(values=colors)+
  scale_x_continuous(breaks=unique(stat.mrd$Time)))+
  scale_alpha_manual(values=c(0.3,0.2,0.2,0.2,0.1))

#Plot mean rooting depth over time
#One line per rhizobox
(p10<-ggplot(root.depth, aes(x=Time, y=mrd, color=Treatment, group=Rz))+
  geom_line()+
  theme_bw()+
  theme(legend.title=element_blank(),
        axis.text=element_text(size=10, color="black"),
        axis.title.y = element_text(margin=margin(r=10)),
        axis.title.x = element_text(margin=margin(t=10)))+
  ylab("MRD (cm)")+
  xlab("Time (days)")+
  scale_color_manual(values=colors)+
  scale_fill_manual(values=colors))

#Plot mean rooting depth at last observation date

(p11<-ggplot(root.depth[root.depth$Time==44,], aes(x=Treatment, y=mrd, colour=Treatment)) +
    geom_jitter(width=0.1, shape=1) + 
    stat_summary(fun.data="mean_cl_boot")+
    ylab("MRD (cm)")+
    xlab("")+ 
    theme_bw()+
    scale_color_manual(values=colors)+
    theme(legend.title=element_blank(),
          axis.text=element_text(size=10, color="black"),
          axis.title.y = element_text(margin=margin(r=10)),
          axis.title.x = element_text(margin=margin(t=10))))

model<-glm(-mrd~Treatment, root.depth[root.depth$Time==44,], family=Gamma(link="log"))

summary(model)
## 
## Call:
## glm(formula = -mrd ~ Treatment, family = Gamma(link = "log"), 
##     data = root.depth[root.depth$Time == 44, ])
## 
## Deviance Residuals: 
##      Min        1Q    Median        3Q       Max  
## -0.30397  -0.07424  -0.03283   0.08887   0.29066  
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       2.63376    0.05658  46.553  < 2e-16 ***
## TreatmentF-first -0.14002    0.08328  -1.681 0.105151    
## TreatmentG-first -0.33800    0.08328  -4.059 0.000426 ***
## TreatmentL-first -0.09670    0.08328  -1.161 0.256555    
## TreatmentSync2   -0.28306    0.08765  -3.230 0.003456 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for Gamma family taken to be 0.02240579)
## 
##     Null deviance: 1.02164  on 29  degrees of freedom
## Residual deviance: 0.55447  on 25  degrees of freedom
## AIC: 125.24
## 
## Number of Fisher Scoring iterations: 4
summary(emmeans(model, "Treatment", contr="tukey"), type="response")
## $emmeans
##  Treatment response    SE  df asymp.LCL asymp.UCL
##  Sync1        13.93 0.788 Inf     12.46      15.6
##  F-first      12.11 0.740 Inf     10.74      13.6
##  G-first       9.93 0.607 Inf      8.81      11.2
##  L-first      12.64 0.773 Inf     11.22      14.3
##  Sync2        10.49 0.702 Inf      9.20      12.0
## 
## Confidence level used: 0.95 
## Intervals are back-transformed from the log scale 
## 
## $contrasts
##  contrast              ratio     SE  df z.ratio p.value
##  Sync1 / (F-first)     1.150 0.0958 Inf  1.681  0.4455 
##  Sync1 / (G-first)     1.402 0.1168 Inf  4.059  0.0005 
##  Sync1 / (L-first)     1.102 0.0917 Inf  1.161  0.7736 
##  Sync1 / Sync2         1.327 0.1163 Inf  3.230  0.0109 
##  (F-first) / (G-first) 1.219 0.1053 Inf  2.291  0.1477 
##  (F-first) / (L-first) 0.958 0.0828 Inf -0.501  0.9873 
##  (F-first) / Sync2     1.154 0.1046 Inf  1.578  0.5115 
##  (G-first) / (L-first) 0.786 0.0679 Inf -2.792  0.0418 
##  (G-first) / Sync2     0.947 0.0858 Inf -0.606  0.9742 
##  (L-first) / Sync2     1.205 0.1092 Inf  2.056  0.2394 
## 
## P value adjustment: tukey method for comparing a family of 5 estimates 
## Tests are performed on the log scale
summary(emmeans(model, "Treatment", contr="tukey"))
## $emmeans
##  Treatment emmean     SE  df asymp.LCL asymp.UCL
##  Sync1       2.63 0.0566 Inf      2.52      2.74
##  F-first     2.49 0.0611 Inf      2.37      2.61
##  G-first     2.30 0.0611 Inf      2.18      2.42
##  L-first     2.54 0.0611 Inf      2.42      2.66
##  Sync2       2.35 0.0669 Inf      2.22      2.48
## 
## Results are given on the log (not the response) scale. 
## Confidence level used: 0.95 
## 
## $contrasts
##  contrast              estimate     SE  df z.ratio p.value
##  Sync1 - (F-first)       0.1400 0.0833 Inf  1.681  0.4455 
##  Sync1 - (G-first)       0.3380 0.0833 Inf  4.059  0.0005 
##  Sync1 - (L-first)       0.0967 0.0833 Inf  1.161  0.7736 
##  Sync1 - Sync2           0.2831 0.0876 Inf  3.230  0.0109 
##  (F-first) - (G-first)   0.1980 0.0864 Inf  2.291  0.1477 
##  (F-first) - (L-first)  -0.0433 0.0864 Inf -0.501  0.9873 
##  (F-first) - Sync2       0.1430 0.0906 Inf  1.578  0.5115 
##  (G-first) - (L-first)  -0.2413 0.0864 Inf -2.792  0.0418 
##  (G-first) - Sync2      -0.0549 0.0906 Inf -0.606  0.9742 
##  (L-first) - Sync2       0.1864 0.0906 Inf  2.056  0.2394 
## 
## Results are given on the log (not the response) scale. 
## P value adjustment: tukey method for comparing a family of 5 estimates

Fit linear mixed effect model

#Calculate number of days after first sowing (dafs)
root.depth$dafs<-root.depth$Time
root.depth$dafs[root.depth$Treatment=="Sync2"]<-root.depth$dafs[root.depth$Treatment=="Sync2"]-10
root.depth1<-root.depth[root.depth$dafs>=0,]

#Fit linear mixed-effect model(random slope and random intercept)
model<-lmer(mrd~Treatment*dafs+(dafs|Rz), root.depth1)
summary(model)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: mrd ~ Treatment * dafs + (dafs | Rz)
##    Data: root.depth1
## 
## REML criterion at convergence: 1772.9
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.26256 -0.74260 -0.01945  0.52662  2.66341 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  Rz       (Intercept) 0.187949 0.43353       
##           dafs        0.002509 0.05009  -0.78
##  Residual             1.179921 1.08624       
## Number of obs: 550, groups:  Rz, 30
## 
## Fixed effects:
##                        Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)           -2.560677   0.253685 24.481732 -10.094 3.32e-10 ***
## TreatmentF-first       0.569123   0.373414 24.481732   1.524 0.140297    
## TreatmentG-first       1.691435   0.373414 24.481732   4.530 0.000132 ***
## TreatmentL-first      -0.557052   0.373414 24.481732  -1.492 0.148531    
## TreatmentSync2         0.404498   0.407078 28.175537   0.994 0.328846    
## dafs                  -0.272964   0.020310 23.542969 -13.440 1.56e-12 ***
## TreatmentF-first:dafs  0.019003   0.029896 23.542969   0.636 0.531146    
## TreatmentG-first:dafs  0.064984   0.029896 23.542969   2.174 0.040025 *  
## TreatmentL-first:dafs  0.022452   0.029896 23.542969   0.751 0.460085    
## TreatmentSync2:dafs    0.002807   0.032682 27.403448   0.086 0.932189    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) TrtmF- TrtmG- TrtmL- TrtmS2 dafs   TrtF-: TrtG-: TrtL-:
## TrtmntF-frs -0.679                                                        
## TrtmntG-frs -0.679  0.462                                                 
## TrtmntL-frs -0.679  0.462  0.462                                          
## TrtmntSync2 -0.623  0.423  0.423  0.423                                   
## dafs        -0.713  0.485  0.485  0.485  0.444                            
## TrtmntF-fr:  0.485 -0.713 -0.329 -0.329 -0.302 -0.679                     
## TrtmntG-fr:  0.485 -0.329 -0.713 -0.329 -0.302 -0.679  0.462              
## TrtmntL-fr:  0.485 -0.329 -0.329 -0.713 -0.302 -0.679  0.462  0.462       
## TrtmntSyn2:  0.443 -0.301 -0.301 -0.301 -0.736 -0.621  0.422  0.422  0.422
plot(model)

#Plot model fit
#One line per rhizobox
(p12<-ggplot(root.depth1, aes(x=dafs, y=mrd, color=Treatment, group=Rz))+
  geom_line(data = cbind(root.depth1, pred = predict(model)), aes(y = pred), size = 1)+
  geom_point(shape=16)+
  theme_bw()+
  theme(legend.title=element_blank(),
        axis.text=element_text(size=10, color="black"),
        axis.title.y = element_text(margin=margin(r=10)),
        axis.title.x = element_text(margin=margin(t=10)))+
  ylab("MRD (cm)")+
  xlab("Days after sowing")+
  scale_color_manual(values=colors)+
  scale_fill_manual(values=colors)+
  scale_x_continuous(limits=c(1, 44)))

pred.mm <- ggpredict(model, terms = c("dafs [1,2,4,6,7,8,9,11,13,14,15,16,18,20,21,22,23,25,27,28,29,30,32,34,35,37,39,42,44]", "Treatment"))

data.mm<-data.frame(dafs=pred.mm$x,
                    Pred=pred.mm$predicted,
                    Treatment=pred.mm$group,
                    CIlow=pred.mm$conf.low,
                    CIhigh=pred.mm$conf.high)

data.mm<-data.mm[-which(data.mm$Treatment=="Sync2" & data.mm$dafs>34),]
data.mm<-data.mm[-which(data.mm$Treatment!="Sync2" & data.mm$dafs<2),]

#Plot model fit
(p13<-ggplot(data.mm) + 
    geom_line(aes(x = dafs, y = Pred, group=Treatment, color=Treatment), size=1) +   
    geom_ribbon(aes(x = dafs, ymin = CIlow, ymax = CIhigh, fill=Treatment, alpha=Treatment)) +
    ylab("MRD (cm)")+
    xlab("Days after sowing")+ 
    theme_bw()+
    scale_color_manual(values=colors)+
    scale_fill_manual(values=colors)+
    theme(legend.title=element_blank(),
          axis.text=element_text(size=10, color="black"),
          axis.title.y = element_text(margin=margin(r=10)),
          axis.title.x = element_text(margin=margin(t=10)))+
    scale_alpha_manual(values=c(0.3,0.2,0.2,0.2,0.1)))

Correlation between MRD biomass and MRD images

root1<-root1[order(root1$Rz),] #Contain MRD values calculated from root biomass
root1$MRDrp<-root.depth[root.depth$Time==44,"mrd"]

corrMRD<-data.frame(MRDb=root1$MRD,
                    MRDi=root1$MRDrp,
                    Treatment=root1$Treatment)

(p14<-ggplot(corrMRD, aes(x=-MRDi, y=MRDb, colour=Treatment))+
      geom_smooth(method="lm", colour="black")+
      geom_point(shape=16)+
      theme_bw()+
      theme(legend.title = element_blank(),
            axis.text=element_text(size=10, color="black"),
            axis.title.y = element_text(margin=margin(r=10)),
            axis.title.x = element_text(margin=margin(t=10)))+
      scale_color_manual(values=colors)+
      xlab("MRD - image analysis (cm)")+
      ylab("MRD - biomass (cm)"))

Create figure MRD over time

text.size<-8
title.size<-9

p14<-ggplot(corrMRD, aes(x=-MRDi, y=MRDb, colour=Treatment))+
      geom_smooth(method="lm", colour="black", size=1)+
      geom_point(shape=16)+
      theme_bw()+
      theme(legend.title=element_blank(),
            legend.position=c(0.85,0.24),
            legend.text=element_text(size=7),
            legend.key.size = unit(0.7, "line"),
            legend.background = element_blank(),
            axis.text=element_text(size=text.size, color="black"),
            axis.title=element_text(size=title.size),
            axis.title.y = element_text(margin=margin(r=5)),
            axis.title.x = element_text(margin=margin(t=5)))+
      scale_color_manual(values=colors)+
      xlab("MRD - image analysis (cm)")+
      ylab("MRD - biomass (cm)")

p9<-ggplot(stat.mrd, aes(x=Time, y=meanValue, color=Treatment))+
  geom_ribbon(aes(ymin=lower, ymax=upper, fill=Treatment, alpha=Treatment), color=NA)+
  geom_line()+
  geom_point(shape=16, size=1)+
  geom_vline(xintercept=10, linetype=3)+
  theme_bw()+
  theme(legend.title=element_blank(),
        legend.position=c(0.85,0.82),
        legend.text=element_text(size=7),
        legend.key.size = unit(0.7, "line"),
        legend.background = element_blank(),
        axis.text=element_text(size=text.size, color="black"),
        axis.title=element_text(size=title.size),
        axis.title.y = element_text(margin=margin(r=5)),
        axis.title.x = element_text(margin=margin(t=5)),
        panel.grid.minor = element_blank())+
  ylab("Mean rooting depth (cm)")+
  xlab("Time (days)")+
  scale_color_manual(values=colors)+
  scale_fill_manual(values=colors)+
  scale_x_continuous(breaks=unique(root.depth$Time),
                     labels=c(2,4,"",9,"","",16,"","",23,"","",30,"","",37, "","",44))+
  scale_alpha_manual(values=c(0.2,0.2,0.2,0.2,0.1))

p13<-ggplot(data.mm) + 
    geom_line(aes(x = dafs, y = Pred, group=Treatment, color=Treatment), size=0.6) +
    geom_ribbon(aes(x = dafs, ymin = CIlow, ymax = CIhigh, fill=Treatment, alpha=Treatment), color=NA) +
    ylab("Mean rooting depth (cm)")+
    xlab("Days after sowing")+ 
    theme_bw()+
    scale_color_manual(values=colors)+
    scale_fill_manual(values=colors)+
    theme(legend.position="none",
          axis.text=element_text(size=text.size, color="black"),
          axis.title=element_text(size=title.size),
          axis.title.y = element_text(margin=margin(r=5)),
          axis.title.x = element_text(margin=margin(t=5)),
          panel.grid.minor = element_blank())+
    scale_alpha_manual(values=c(0.2,0.2,0.2,0.2,0.1))+
    scale_x_continuous(breaks=seq(0,44, by=4),
                     labels=seq(0,44, by=4))+
    scale_y_continuous(breaks=c(0,-4,-8,-12,-16), labels=c(0,-4,-8,-12,-16), limits=c(-16,0))

(p15<-ggarrange(p14, p9, p13, nrow=1, ncol=3, labels=c("(a)", "(b)", "(c)"), font.label = list(size=11)))

#ggsave("Figure5.tiff", p15, dpi=1000, compression="lzw", width=20, height=6, units="cm")