9  Analyse Root Architecture dependent of the depth

Code
#package ----
library(tidyr)
library(readxl)
library(ggplot2)
library(plotly)
library(vroom)
library(ggExtra)
library(gridExtra)
library(ggpubr)
library(cowplot)  # for plotgrid
library(stringr)
library(gt)
library(dplyr)
library(gt)       # gramar table
library(DT)
library(tidyverse)
library(here)
library(patchwork)
library(psych)    # for correlation
library(PerformanceAnalytics) # for correlation

#src
source(here::here("src/function/graph_function.R")) # personal graphic
source(here::here("src/function/stat_function/stat_analysis_main.R")) # to make plot 


# cosmetics
climate_pallet=read_excel(here::here("data/color_palette.xlsm")) %>%
      filter(set == "climat_condition") %>%
      dplyr::select(color, treatment) %>%
      pull(color) %>%
      setNames(read_excel(here::here("data/color_palette.xlsm")) %>%
                 filter(set == "climat_condition") %>%
                 pull(treatment)
               )

9.1 Data importation

Code
coo_root_tips_select=read.csv(here::here("data/root/output/coo_root_tips_select.csv"))%>% 
  mutate(climat_condition=factor(climat_condition,levels=c("WW_OT","WS_OT","WW_HS","WS_HS"))) %>% 
  mutate(condition=factor(condition,levels=c("Sto_WW_OT","Sto_WS_OT","Sto_WW_HS","Sto_WS_HS","Wen_WW_OT","Wen_WS_OT","Wen_WW_HS","Wen_WS_HS")))

coo_root_angle_select=read.csv(here::here("data/root/output/coo_root_angle_select.csv"))%>%  mutate(condition=factor(condition,levels=c("Sto_WW_OT","Sto_WS_OT","Sto_WW_HS","Sto_WS_HS","Wen_WW_OT","Wen_WS_OT","Wen_WW_HS","Wen_WS_HS"))) %>% 
  mutate(climat_condition=factor(climat_condition,levels=c("WW_OT","WS_OT","WW_HS","WS_HS"))) 

9.1.1 Angle

Is there a difference in angle depending on the depth in the rhizotube?

Code
a=1 ; b=10
coo_root_angle_select$cut_break=cut(coo_root_angle_select$YB_calc_cm,breaks = c(seq(0,45+a,a)),
                       labels=c(seq(0,45,a)),include.lowest = TRUE)
p2=coo_root_angle_select %>% 
  filter(!is.na(YB_calc_cm)) %>% 
  filter(!is.na(cut_break)) %>% 
  filter(YB_calc_cm<45) %>% 
  filter(branching==1) %>% ####### warning
  ggplot(aes(x=as.numeric(as.character(cut_break)),y=Angle_ABC,colour=as.factor(condition))) +
  stat_summary(aes(group=as.factor(condition)),fun=mean,geom="line",size=1,alpha=0.85)+
  scale_x_continuous(limits =c(0,45))+xlab("Profondeur (cm")+ylab("Angle ABC (°)")+
  geom_vline(xintercept = seq(0,45,b) , linetype="dashed", 
             color = "black", size=1)+ 
  ggtitle(paste("Mean eatch", a, "cm for line, for dashed line every",b, "cm",sep=" "))+
  scale_color_manual(values=climate_pallet)
p2

#with smooth function ?
p3=coo_root_angle_select %>% 
  filter(!is.na(YB_calc_cm)) %>% 
  filter(!is.na(cut_break)) %>% 
  filter(YB_calc_cm<45) %>% 
  filter(branching==1) %>% ####### warning
  #ggplot(aes(x=as.numeric(as.numeric(cut_break)*a),y=Angle_ABC,colour=as.factor(climat_condition),fill=as.factor(climat_condition)))+
  ggplot(aes(x=as.numeric(as.numeric(cut_break)*a),y=Angle_ABC,colour=as.factor(climat_condition),fill=as.factor(climat_condition),linetype=genotype))+ #trop lourd
  geom_smooth(alpha=.15)+
  #geom_point()+
  geom_vline(xintercept = seq(0,45,b) , linetype="dashed", 
             color = "black", size=1)+ 
  #ggtitle(paste("Mean eatch", a, "cm for line, for dashed line every",b, "cm for branching 1",sep=" "))+
  scale_color_manual(values=climate_pallet)+
  scale_fill_manual(values=climate_pallet)+
  coord_flip() + 
  scale_x_reverse()+
  labs(color="Treatment",fill="Treatment",linetype="Genotype")+
  theme_bw()+
  theme(panel.grid.major = element_blank(),
  panel.grid.minor = element_blank(),
  legend.position = "none")+
  xlab("Depth in cm")+ylab("Angle ABC (°) each 1cm")

export_fig(p=p3,export_path = here::here("report/root_architecture/plot/angle_ABC_branching_1_by_profondeur_each_1cm.png"),export_height = 20,export_width = 24)

Verification of the hypothesis for a certain depth

Code
a=1 ; b=10
coo_root_angle_select$cut_break=cut(coo_root_angle_select$YB_calc_cm,breaks = c(seq(0,60,10)),
                       labels=c(seq(0,50,10)),include.lowest = TRUE)
profondeurs=seq(0,40,10)

plots <- lapply(1:length(profondeurs), function(i) {
  angle_for_plettre<-coo_root_angle_select %>%
    filter(branching==1) %>%
    #filter(plant_num!=1005) %>%
    filter(cut_break ==profondeurs[i]) %>%  
    dplyr::group_by(condition,heat_condition,water_condition,genotype,plant_num) %>%
    dplyr::summarise(across(Angle_ABC:Angle_C2BD2, \(x) mean(x,na.rm=T)))%>%
    mutate(condition=factor(condition,levels=c("Wen_WW_OT","Wen_WW_HS","Wen_WS_OT","Wen_WS_HS","Sto_WW_OT","Sto_WW_HS","Sto_WS_OT","Sto_WS_HS")))
  
FigX_stat=stat_analyse(
    data=angle_for_plettre %>% 
      mutate(climat_condition=paste0(water_condition,"_",heat_condition)) %>% 
      mutate(condition=factor(condition,levels=c("Sto_WW_OT","Stoc_WS_OT","Sto_WW_HS","Sto_WS_HS","Wen_WW_OT","Wen_WS_OT","Wen_WW_HS","Wen_WS_HS"))) %>% 
    mutate(climat_condition=factor(climat_condition,levels=c("WW_OT","WS_OT","WW_HS","WS_HS"))) %>% 
      drop_na(climat_condition,Angle_ABC),
    column_value = "Angle_ABC",
    category_variables = c("climat_condition"),
    grp_var = "genotype",
    show_plot = T,
    outlier_show = F, 
    label_outlier = "plant_num",
    biologist_stats = T,
    Ylab_i =  paste0("Mean of angle ABC \n",profondeurs[i]," to ",profondeurs[i]+10,"cm (°) for branching 1"),
  control_conditions = c("WW_OT"),
  strip_normale = F,
  hex_pallet = climate_pallet
)
px=FigX_stat[["plot"]] +  theme(axis.title.x=element_blank(),axis.text.x=element_blank(),panel.grid.major = element_blank(),
  panel.grid.minor = element_blank(),legend.position = "right",plot.margin=unit(c(0.1,0.1,0.7,0.1), "cm"))#,plot.caption = element_text(vjust = 10))
print(px)+labs(color="Treatment",fill="Treatment")
})

# Assembling graphics
final_plot <- wrap_plots(plots, ncol = 2)+ 
  plot_layout(guides = "collect")+
  guide_area()+
  plot_annotation(tag_levels = 'A',
                  title="Combined graph of Angle depending of the depth in soil for angle ABC",
                  subtitle="19DAP")

png(here::here("report/root_architecture/plot/angle_ABC_depending_depth_19DAP_condition.png"), width = 16, height = 22, units = 'cm', res = 900)
final_plot
dev.off()

9.1.2 Number of tips

The number of root tips depending on the depth?

Code
a=1 ; b=10
coo_root_tips_select$cut_break=cut(coo_root_tips_select$cm,breaks = c(seq(0,45+a,a)),
                       labels=c(seq(0,45,a)),include.lowest = TRUE)
p4=coo_root_tips_select %>% 
  filter(!is.na(cm)) %>% 
  filter(!is.na(cut_break)) %>% 
  filter(cm<45) %>% 
  ggplot(aes(x=as.numeric(as.character(cut_break)),y=X,colour=as.factor(condition))) +
  stat_summary(aes(group=as.factor(condition)),fun=length,geom="line",size=1,alpha=0.85)+
  scale_x_continuous(limits =c(0,45))+xlab("Profondeur (cm")+ylab("Number of root tips")+
  geom_vline(xintercept = seq(0,45,b) , linetype="dashed", 
             color = "black", size=1)+ 
  ggtitle(paste("Mean eatch", a, "cm for line, for dashed line every (need verification because huge nuber of root tips",b, "cm",sep=" "))+
  scale_color_manual(values=climate_pallet)
p4
#export_png(p=p4,export_path = here::here(paste0("xp1_analyse/plot/root_architecture/by_profondeur/nb_tips_by_profondeur_cm.png")),export_height = 20,export_width = 24)

#with smooth
p5=  coo_root_tips_select %>% 
  filter(!is.na(cm)) %>% 
  filter(!is.na(cut_break)) %>% 
  filter(cm<45) %>% 
  dplyr::group_by(climat_condition,heat_condition,water_condition,genotype,plant_num,cut_break) %>% 
  dplyr::summarise(nb_tips = n()) %>%
  ggplot(aes(x=as.numeric(as.numeric(cut_break)*a),y=nb_tips,colour=climat_condition,fill=climat_condition,linetype=genotype))+
  geom_smooth(alpha=.15)+
  #geom_point()+
  geom_vline(xintercept = seq(0,45,b) , linetype="dashed", 
             color = "black", size=1)+ 
  # ggtitle(paste("Mean eatch", a, "cm for line, for dashed line every",b, "cm using smooth",sep=" "))+
  scale_color_manual(values=climate_pallet)+
  ylab ("Number of tips each 1 cm in depth")+
  xlab("Depth in cm")+
  scale_fill_manual(values=climate_pallet)+
  coord_flip() + 
  scale_x_reverse() +
  labs(color="Treatment",fill="Treatment",linetype="Genotype")+
  theme_bw()+
  theme(panel.grid.major = element_blank(),
  panel.grid.minor = element_blank(),
  legend.position = "none")
  
#p3=p3+xlab("Depth in cm")+ylab("Mean angle ABC (°) each 1cm")
#  scale_y_continuous(trans = "reverse")
p5

export_fig(type = "png",p=p5,export_path = here::here(paste0("report/root_architecture/plot/nb_tips_by_profondeur_cm_smooth_mean1cm.png")),export_height = 20,export_width = 24)

Verification of the hypothesis for a certain depth

Code
a=1 ; b=10
coo_root_tips_select$cut_break=cut(coo_root_tips_select$cm,breaks = c(seq(0,60,10)),
                       labels=c(seq(0,50,10)),include.lowest = TRUE)
profondeurs=seq(0,40,10)

tips_for_plettre <- lapply(1:length(profondeurs), function(i) {
  tips_for_plettre<-coo_root_tips_select %>%
    filter(plant_num!=1005) %>%
    filter(cut_break ==profondeurs[i]) %>%
    dplyr::group_by(condition,heat_condition,water_condition,genotype,plant_num) %>%
    dplyr::summarise(nb_tips = n()) %>%
    mutate(condition=factor(condition,levels=c("Wen_WW_OT","Wen_WW_HS","Wen_WS_OT","Wen_WS_HS","Sto_WW_OT","Sto_WW_HS","Sto_WS_OT","Sto_WS_HS")))
    #filter(branching==1)
    
  FigX_stat=stat_analyse(
      data=tips_for_plettre %>% 
        mutate(climat_condition=paste0(water_condition,"_",heat_condition)) %>% 
        mutate(condition=factor(condition,levels=c("Sto_WW_OT","Stoc_WS_OT","Sto_WW_HS","Sto_WS_HS","Wen_WW_OT","Wen_WS_OT","Wen_WW_HS","Wen_WS_HS"))) %>% 
      mutate(climat_condition=factor(climat_condition,levels=c("WW_OT","WS_OT","WW_HS","WS_HS"))) %>% 
        drop_na(climat_condition,nb_tips) %>% 
        as.data.frame(),
      column_value = "nb_tips",
      category_variables = c("climat_condition"),
      grp_var = "genotype",
      show_plot = T,
      outlier_show = F, 
      label_outlier = "plant_num",
      biologist_stats = T,
      Ylab_i =  paste0("Number of tips in ",profondeurs[i]," to ",profondeurs[i] + 10," cm"),
    control_conditions = c("WW_OT"),
    strip_normale = F,
    hex_pallet = climate_pallet
  )
  px=FigX_stat[["plot"]] +  theme(axis.title.x=element_blank(),axis.text.x=element_blank(),panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),legend.position = "right",plot.margin=unit(c(0.1,0.1,0.7,0.1), "cm"))#,plot.caption = element_text(vjust = 10))
  print(px)+labs(color="Treatment",fill="Treatment")
})

# Assembling graphics
final_plot <- wrap_plots(plots, ncol = 2)+ 
  plot_layout(guides = "collect")+
  guide_area()+
  plot_annotation(tag_levels = 'A',
                  title="Combined graph of the number of tips depending of the depth in soil (each 10cm)",
                  subtitle="19DAP")

png(here::here("report/root_architecture/plot/nb_tips_depending_depth_19DAP_condition.png"), width = 16, height = 22, units = 'cm', res = 900)
final_plot
dev.off()

Again we have very good result depending of the depth

9.2 Figure for the publication

Code
# part stats to compile (only 10 to 20 and 30 to 40) ######
a=1 ; b=10
coo_root_tips_select$cut_break=cut(coo_root_tips_select$cm,breaks = c(seq(0,60,10)),
                       labels=c(seq(0,50,10)),include.lowest = TRUE)
profondeurs=seq(0,40,10)

##### tipe 10 to 20
tips_for_plettre<-coo_root_tips_select %>%
    filter(plant_num!=1005) %>%
    filter(cut_break ==profondeurs[2]) %>%
    dplyr::group_by(condition,heat_condition,water_condition,genotype,plant_num) %>%
    dplyr::summarise(nb_tips = n()) %>%
    mutate(condition=factor(condition,levels=c("Stp_WW_OT","Sto_WW_HS","Sto_WS_OT","Sto_WS_HS","Wen_WW_OT","Wen_WW_HS","Wen_WS_OT","Wen_WS_HS")))
    #filter(branching==1)
    
FigX_stat=stat_analyse(
    data=tips_for_plettre %>% 
      mutate(climat_condition=paste0(water_condition,"_",heat_condition)) %>% 
      mutate(condition=factor(condition,levels=c("Sto_WW_OT","Stoc_WS_OT","Sto_WW_HS","Sto_WS_HS","Wen_WW_OT","Wen_WS_OT","Wen_WW_HS","Wen_WS_HS"))) %>% 
    mutate(climat_condition=factor(climat_condition,levels=c("WW_OT","WS_OT","WW_HS","WS_HS"))) %>% 
      drop_na(climat_condition,nb_tips) %>% 
      as.data.frame(),
    column_value = "nb_tips",
    category_variables = c("climat_condition"),
    grp_var = "genotype",
    show_plot = T,
    outlier_show = F, 
    label_outlier = "plant_num",
    biologist_stats = T,
    Ylab_i =  paste0("Number of tips in ",profondeurs[2]," to ",profondeurs[2] + 10," cm"),
  control_conditions = c("WW_OT"),
  strip_normale = F,
  hex_pallet = climate_pallet
)

px1=FigX_stat[["plot"]] +  theme(axis.title.x=element_blank(),axis.text.x=element_blank(),panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),legend.position = "bottom",plot.margin=unit(c(0.1,0.1,0.7,0.1), "cm"))+ylim(0,250)+
    labs(color="Treatment",fill="Treatment")

#### tips 30 to 40
tips_for_plettre<-coo_root_tips_select %>%
    filter(plant_num!=1005) %>%
    filter(cut_break ==profondeurs[4]) %>%
    dplyr::group_by(condition,heat_condition,water_condition,genotype,plant_num) %>%
    dplyr::summarise(nb_tips = n()) %>%
    mutate(condition=factor(condition,levels=c("Wen_WW_OT","Wen_WW_HS","Wen_WS_OT","Wen_WS_HS","Sto_WW_OT","Sto_WW_HS","Sto_WS_OT","Sto_WS_HS")))
    #filter(branching==1)
    
FigX_stat=stat_analyse(
    data=tips_for_plettre %>% 
      mutate(climat_condition=paste0(water_condition,"_",heat_condition)) %>% 
      mutate(condition=factor(condition,levels=c("Sto_WW_OT","Stoc_WS_OT","Sto_WW_HS","Sto_WS_HS","Wen_WW_OT","Wen_WS_OT","Wen_WW_HS","Wen_WS_HS"))) %>% 
    mutate(climat_condition=factor(climat_condition,levels=c("WW_OT","WS_OT","WW_HS","WS_HS"))) %>% 
      drop_na(climat_condition,nb_tips) %>% 
      as.data.frame(),
    column_value = "nb_tips",
    category_variables = c("climat_condition"),
    grp_var = "genotype",
    show_plot = T,
    outlier_show = F, 
    label_outlier = "plant_num",
    biologist_stats = T,
    Ylab_i =  paste0("Number of tips in ",profondeurs[4]," to ",profondeurs[4] + 10," cm"),
  control_conditions = c("WW_OT"),
  strip_normale = F,
  hex_pallet = climate_pallet
)

px2=FigX_stat[["plot"]] +  theme(axis.title.x=element_blank(),axis.text.x=element_blank(),panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),legend.position = "bottom",plot.margin=unit(c(0.1,0.1,0.7,0.1), "cm"))+ylim(0,250)+labs(color="Treatment",fill="Treatment")

###### angle 10 to 20
a=1 ; b=10
coo_root_angle_select$cut_break=cut(coo_root_angle_select$YB_calc_cm,breaks = c(seq(0,60,10)),
                       labels=c(seq(0,50,10)),include.lowest = TRUE)
profondeurs=seq(0,40,10)

angle_for_plettre<-coo_root_angle_select %>%
    filter(branching==1) %>%
    #filter(plant_num!=1005) %>%
    filter(cut_break ==profondeurs[3]) %>%  
    dplyr::group_by(condition,heat_condition,water_condition,genotype,plant_num) %>%
    dplyr::summarise(across(Angle_ABC:Angle_C2BD2, \(x) mean(x,na.rm=T)))%>%
    mutate(condition=factor(condition,levels=c("Wen_WW_OT","Wen_WW_HS","Wen_WS_OT","Wen_WS_HS","Sto_WW_OT","Sto_WW_HS","Sto_WS_OT","Sto_WS_HS")))
  
FigX_stat=stat_analyse(
    data=angle_for_plettre %>% 
      mutate(climat_condition=paste0(water_condition,"_",heat_condition)) %>% 
      mutate(condition=factor(condition,levels=c("Sto_WW_OT","Stoc_WS_OT","Sto_WW_HS","Sto_WS_HS","Wen_WW_OT","Wen_WS_OT","Wen_WW_HS","Wen_WS_HS"))) %>% 
    mutate(climat_condition=factor(climat_condition,levels=c("WW_OT","WS_OT","WW_HS","WS_HS"))) %>% 
      drop_na(climat_condition,Angle_ABC) %>% 
      filter(plant_num != 1094) %>% 
      as.data.frame(),
    column_value = "Angle_ABC",
    category_variables = c("climat_condition"),
    grp_var = "genotype",
    show_plot = T,
    outlier_show = F, 
    label_outlier = "plant_num",
    biologist_stats = T,
    Ylab_i =  paste0("Angle ABC \n",profondeurs[3]," to ",profondeurs[3]+10," cm (°) for branching 1"),
  control_conditions = c("WW_OT"),
  strip_normale = F,
  hex_pallet = climate_pallet
)
px3=FigX_stat[["plot"]] +  theme(axis.title.x=element_blank(),axis.text.x=element_blank(),panel.grid.major = element_blank(),
  panel.grid.minor = element_blank(),legend.position = "right",plot.margin=unit(c(0.1,0.1,0.7,0.1), "cm"))+ylim(55,102)+labs(color="Treatment",fill="Treatment")

###### angle 30 to 40

a=1 ; b=10
coo_root_angle_select$cut_break=cut(coo_root_angle_select$YB_calc_cm,breaks = c(seq(0,60,10)),
                       labels=c(seq(0,50,10)),include.lowest = TRUE)
profondeurs=seq(0,40,10)

angle_for_plettre<-coo_root_angle_select %>%
    filter(branching==1) %>%
    filter(plant_num!=1005) %>%
    filter(cut_break ==profondeurs[4]) %>%  
    dplyr::group_by(condition,heat_condition,water_condition,genotype,plant_num) %>%
    dplyr::summarise(across(Angle_ABC:Angle_C2BD2, \(x) mean(x,na.rm=T)))%>%
    mutate(condition=factor(condition,levels=c("Wen_WW_OT","Wen_WW_HS","Wen_WS_OT","Wen_WS_HS","Sto_WW_OT","Sto_WW_HS","Sto_WS_OT","Sto_WS_HS")))
  
FigX_stat=stat_analyse(
    data=angle_for_plettre %>% 
      mutate(climat_condition=paste0(water_condition,"_",heat_condition)) %>% 
      mutate(condition=factor(condition,levels=c("Sto_WW_OT","Stoc_WS_OT","Sto_WW_HS","Sto_WS_HS","Wen_WW_OT","Wen_WS_OT","Wen_WW_HS","Wen_WS_HS"))) %>% 
    mutate(climat_condition=factor(climat_condition,levels=c("WW_OT","WS_OT","WW_HS","WS_HS"))) %>% 
      drop_na(climat_condition,Angle_ABC) %>% 
      as.data.frame(),
    column_value = "Angle_ABC",
    category_variables = c("climat_condition"),
    grp_var = "genotype",
    show_plot = T,
    outlier_show = F, 
    label_outlier = "plant_num",
    biologist_stats = T,
    Ylab_i =  paste0("Angle ABC \n",profondeurs[4]," to ",profondeurs[4]+10," cm (°) for branching 1"),
  control_conditions = c("WW_OT"),
  strip_normale = F,
  hex_pallet = climate_pallet
)
px4=FigX_stat[["plot"]] + theme(axis.title.x=element_blank(),axis.text.x=element_blank(),panel.grid.major = element_blank(),
  panel.grid.minor = element_blank(),legend.position = "bottom",plot.margin=unit(c(0.1,0.1,0.7,0.1), "cm"))+ylim(55,102)+labs(color="Treatment",fill="Treatment")

final_plot=ggarrange(p5,p3,ncol=1,widths = c(1, 1), nrow=2,labels = c("A","D"),legend="bottom",common.legend = T)

stats_tips_angle=ggarrange(px1,px2,px3,px4,ncol=2, nrow=2,labels = c("B","C","E","F"),legend="bottom",common.legend = T)

plot_final=ggarrange(final_plot ,stats_tips_angle,ncol=2,widths = c(0.9, 0.7), nrow=1,legend="bottom",common.legend = T,align = "v")


# png(here::here("report/root_architecture/plot/fig_publie_angle_nb_tips_depending_depth.png"), width = 32, height = 22, units = 'cm', res = 900)
# plot_final
# dev.off()

svg(here::here("report/root_architecture/plot/fig_publie_angle_nb_tips_depending_depth.svg"), width = 32/2.5, height = 22/2.5)
plot_final
dev.off()