Code
#pkg 
library(tidyverse)
library(patchwork)
library(readxl)

# function
source(here::here("src/function/stat_function/stat_analysis_main.R")) # for make plot 
source(here::here("src/function/fig_export.R")) # This function saves a given plot (plot_x) as both a PDF and a high-resolution PNG file at specified dimensions.

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

3.1 Data importation

Code
# data importation
raw_file <- read_excel(here::here("data/physio/biomass/biomass_verif_modif_CM.xlsx"), col_names = T) %>% 
  dplyr::mutate(genotype = case_when(
        genotype %in% "2684" ~ "W78*",
        genotype %in% "4693" ~ "E568K",
        genotype %in% "CAM2684" ~ "WT1",
        genotype %in% "CAM4693" ~ "WT2", 
        genotype %in% "KAY" ~ "KAY"),
        genotype = forcats::fct_relevel(genotype, "KAY", "WT1", "W78*", "WT2", "E568K"),
        water_condition = forcats::fct_relevel(water_condition, "WW", "WS"),
        condition = paste(sep = "_", genotype, sulfur_condition), 
        sulfur_condition = forcats::fct_relevel(sulfur_condition, "SS", "SD"),
        sampling = forcats::fct_relevel(sampling, "E0", "E1", "E2", "Emat", "ERT"),
        edaphic_condition = paste(sep = "_", water_condition, sulfur_condition), 
        edaphic_condition = forcats::fct_relevel(edaphic_condition, "WW_SS", "WW_SD", "WS_SS", "WS_SD")
  )

raw_file_v <- raw_file %>% pivot_longer(cols = c(""), names_to = "organ", values_to = "DW")

raw_file_v <- raw_file %>%
  mutate(across(contains("DW"), as.numeric)) %>% 
  pivot_longer(
    cols = contains("DW"),             # toutes les colonnes qui finissent par "DW"
    names_to  = "compartment",             # nom de la colonne qui contiendra le nom initial
    values_to = "biomass"                    # nom de la colonne qui contiendra la valeur
  ) 
Code
raw_file_v %>% 
  filter(compartment == "root_nods_DW") %>% 
ggplot(., aes(x=edaphic_condition, y=biomass, fill = edaphic_condition, color = edaphic_condition))+
  facet_grid(genotype~sampling)+
  geom_boxplot(alpha=.5, outlier.shape = NA)+
  geom_jitter()+
  theme_bw()+
  scale_fill_manual(values = pallet)+
  scale_colour_manual(values = pallet)

raw_file_l_biomass_summary = raw_file_v %>% 
  dplyr::group_by(sulfur_condition, water_condition, sampling, genotype, edaphic_condition, condition, compartment) %>% 
  dplyr::summarise(Mean = mean(biomass, na.rm = T), SD = sd(biomass, na.rm = T))

p_final = ggplot(raw_file_l_biomass_summary, aes(x = edaphic_condition, y = Mean, fill = compartment)) +
  #geom_text(position = position_stack(vjust = 1.00),data = df_stats_global_sum, aes(y = Mean_Sum*1.1+.45, label = group),fontface = "bold",color="gray40")+
  facet_grid(genotype~sampling, scales = "free", space = "free") +
  geom_bar(stat = "identity", colour = "black") +
  ylab("Dry biomass of each organ (g)")#+
  # geom_errorbar(
  #   aes(ymin = label_ypos, ymax = label_ypos + SD),
  #   size = 0.5,
  #   width = 0.3,
  #   position = position_identity(),
  #   colour = "black"
  # )+
  #   scale_fill_manual(values = c("#C69C5C", # geno
  #                              "#EEF0D1", 
  #                              "#C3D592", 
  #                              "#97B953", 
  #                              "#3D7E44", 
  #                              "#7F4B1E"), ),
  #                   name = "Compartment") +
  # new_scale_fill() +
  # scale_fill_manual(values = c("#069C74","#E89005"),name ="Sulfur condition")+
  # geom_tile(aes(x = condition, 
  #                         y = -.2,  # Adjust this value to move the rectangles downwards,
  #                        fill = sulfur_condition,
  #                       col = "black",
  #                        width = 0.90,
  #               height = 0.15
  #               ),  
  #                    data = raw_file_l_biomass_summary,
  #           color="black",
  #           size = .5,
  #                    alpha = 1,  
  #                    inherit.aes = FALSE)+
  # geom_text(aes(label = group),  
  #           vjust = 0.5,
  #           color = ifelse(raw_file_l_biomass_summary$variable %in% c("Root", "N0-N8"), "white", "black"),
  #           position = position_stack(vjust = 0.5))+
  # scale_x_discrete(labels = rep(c("WT1", "W78*", "WT2", "E568K"),4))+
  # theme_minimal()+
  # theme(panel.grid = element_blank(),
  #       axis.text.x = element_text(face = "bold",margin = margin(t = -30)),
  #       axis.title.y = element_text(size=12, face="bold"),
  #       axis.title.x = element_blank(),
  #       strip.text = element_text(face = "bold",vjust = 1,size = 12),
  #       strip.background = element_rect(fill = "white", color = "black", size = 0.8),  
  #       strip.placement = "outside",
  #       legend.position = "bottom"
  #       )