# pkglibrary(readxl)library(tidyverse)library(dplyr)# src# source(here::here("src/function/stat_function/stat_analysis_main.R")) # for make plot # source("src/function/graph_function.R")
I not analyse Al, Si, Pb, Ag, Ti and S because the results are not interesting or the variability is too higher
Code
# Exportation of the resultsdf_ionomic_export<-apply(df_ionomic,2,as.character)write.csv(as.data.frame(df_ionomic_export),row.names = F,here::here("data/iono/output/ionomic.csv"))write.csv(as.data.frame(df_ionomic),row.names = F,here::here("data/iono/output/ionomic_with_na.csv"))
## Pre-processing of ionomic data {#sec-iono}```{r setup,message=FALSE, warning=FALSE,echo=T}# pkglibrary(readxl)library(tidyverse)library(dplyr)# src# source(here::here("src/function/stat_function/stat_analysis_main.R")) # for make plot # source("src/function/graph_function.R")```## Data importation```{r}plant_info=read_excel(here::here("data/plant_information.xlsx"))``````{r, results='hide'}# Creation of one function who analyse eatch excel for root, leaf and steamsource(here::here("src/function/iono/import_data_ionomic.R"))#data importation ----list_name_excel=c("ICP-2022-04E-M. Prudent_modif.xlsx","ICP-2022-06E-M. Prudent_modif.xlsx","ICP-2022-07E-M. Prudent_modif.xlsx")list_range=c("A42:AE95","A39:AE92","A40:AE93")list_range_colname=c("B25:AE25","B25:AE25","B25:AE25")list_compartiment=c("leaf","root","stem")df_ionomic=data.frame()for (i in 1:length(list_name_excel)){ print(list_compartiment[i]) df_ionomic_x=import_data_ionomic(name_excel_x=list_name_excel[i],range_data_x=list_range[i],colname_x=list_range_colname[i],compartiment_x=list_compartiment[i]) df_ionomic=rbind(df_ionomic,df_ionomic_x)}df_ionomic$only_C_and_N=NA# Importation of CHN analyse df_chn=read_excel(here::here("data/iono/CHN/tableau résultats Corentin_compile.xlsx"))df_chn_vertical=df_chn %>% pivot_longer(c("N","C"),values_to="concentration",names_to="compound")df_chn_vertical=df_chn_vertical %>% #as_tibble(df_chn_vertical) %>% dplyr::rename(id=Echantillon) %>% as.data.frame()df_chn_vertical=df_chn_vertical %>% group_by(id,compound) %>% dplyr::summarise(concentration=mean(concentration))df_chn_vertical$concentration=df_chn_vertical$concentration*10000df_chn_vertical$compartiment_code=substr(df_chn_vertical$id,start=1,stop=1)df_chn_vertical$plant_num=substr(df_chn_vertical$id,2,nchar(df_chn_vertical$id))df_chn_vertical$compartiment[df_chn_vertical$compartiment_code=="L"] <- "leaf"df_chn_vertical$compartiment[df_chn_vertical$compartiment_code=="S"] <- "stem"df_chn_vertical$compartiment[df_chn_vertical$compartiment_code=="R"] <- "root"df_chn_vertical$compartiment_compound=paste0(df_chn_vertical$compartiment, "_", df_chn_vertical$compound)df_chn_vertical$compound_compartiment=paste0(df_chn_vertical$compound, "_", df_chn_vertical$compartiment)df_chn_vertical$justesse=1df_chn_vertical$color="vert"plant_info=read_excel(here::here("data/plant_information.xlsx"))df_chn_vertical=merge(plant_info,df_chn_vertical,by="plant_num",all.y=T)# Add column only_C_N on plant_info # df_chn_vertical$only_C_and_N=T# Convert x in only_C_N into into Tdf_chn_vertical$only_C_and_N= ifelse(df_chn_vertical$only_C_and_N=="x",T,NA)df_ionomic=rbind(df_ionomic,df_chn_vertical)# Allocation and quantity of ion in eatch plant#1- Importation of the data and mergeBM=read.csv2(here::here("data/physio/global_physio.csv"))df_ionomic$plant_num=as.integer(df_ionomic$plant_num)df_ionomic=merge(df_ionomic, BM %>% dplyr::select(plant_num, weight_root,weight_leaf, weight_stem, leaf_area, stem_area), by= "plant_num", all=T) %>% drop_na(concentration)df_ionomic$weight_total=df_ionomic$weight_leaf+df_ionomic$weight_root+df_ionomic$weight_stem# Corection of the justesse with color# Justessedf_ionomic$note=NAdf_ionomic$correct_concentration=NAfor( i in 1:length(df_ionomic$plant_num)){ if(is.na(df_ionomic$color[i])){next} else if(df_ionomic$color[i]=="jaune"){ df_ionomic$correct_concentration[i]=df_ionomic$concentration[i]/df_ionomic$justesse[i] }else if(df_ionomic$color[i]=="vert"){ df_ionomic$correct_concentration[i]=df_ionomic$concentration[i] }else if (df_ionomic$color[i]=="rouge"){ df_ionomic$correct_concentration[i]=NA df_ionomic$note[i]="[justesse color is red]" }}test=df_ionomic %>% filter(is.na(concentration))# By organedf_ionomic$qty=NAfor(i in 1:length(df_ionomic$plant_num)){ if(is.na(df_ionomic$compartiment_code[i])){next} else if(df_ionomic$compartiment_code[i]=="L"){ df_ionomic$qty[i]=df_ionomic$correct_concentration[i]*df_ionomic$weight_leaf[i] }else if(df_ionomic$compartiment_code[i]=="S"){ df_ionomic$qty[i]=df_ionomic$correct_concentration[i]*df_ionomic$weight_stem[i] }else if(df_ionomic$compartiment_code[i]=="R"){ df_ionomic$qty[i]=df_ionomic$correct_concentration[i]*df_ionomic$weight_root[i] }}# Allocation in %df_ionomic=df_ionomic %>% group_by(plant_num, compound) %>% mutate(sum_by_component=sum(qty, na.rm = T), num_compartiment=n()) %>% mutate(allocation=ifelse(num_compartiment==3,qty/sum_by_component,NA))# Create id for ionomicdf_ionomic$id_sample=paste0( df_ionomic$plant_num, "_", df_ionomic$compartiment_code)df_ionomic$condition_organe=paste0(df_ionomic$condition,"_",df_ionomic$compartiment)# Add type iondf_ionomic$type_ion=NAdf_ionomic$type_ion_num=NAfor (i in 1:length(df_ionomic$compound)){ if( df_ionomic$compound[i]=="C" || df_ionomic$compound[i]=="N" || df_ionomic$compound[i]=="Mg24"|| df_ionomic$compound[i]=="P31"|| df_ionomic$compound[i]=="S32"|| df_ionomic$compound[i]=="K39"|| df_ionomic$compound[i]=="Ca44" ){ df_ionomic$type_ion[i]="essential_macroelement" df_ionomic$type_ion_num[i]=1 } else if ( df_ionomic$compound[i]=="B11" || df_ionomic$compound[i]=="Mn55"|| df_ionomic$compound[i]=="Fe56"|| df_ionomic$compound[i]=="Ni60"|| df_ionomic$compound[i]=="Cu63"|| df_ionomic$compound[i]=="Zn66"|| df_ionomic$compound[i]=="Mo98"|| df_ionomic$compound[i]=="Mo95" ){ df_ionomic$type_ion[i]="essential_microelement" df_ionomic$type_ion_num[i]=2 } else if ( df_ionomic$compound[i]=="Na23" || df_ionomic$compound[i]=="Si28"|| df_ionomic$compound[i]=="Al27"|| df_ionomic$compound[i]=="V51"|| df_ionomic$compound[i]=="Co59"|| df_ionomic$compound[i]=="Se77" ){ df_ionomic$type_ion[i]="beneficial_element" df_ionomic$type_ion_num[i]=3 } else if ( df_ionomic$compound[i]=="Ag107" || df_ionomic$compound[i]=="As75"|| df_ionomic$compound[i]=="Ba137"|| df_ionomic$compound[i]=="Be9"|| df_ionomic$compound[i]=="Cd111"|| df_ionomic$compound[i]=="Cr52"|| df_ionomic$compound[i]=="Pb208"|| df_ionomic$compound[i]=="Rb85"|| df_ionomic$compound[i]=="Sb121"|| df_ionomic$compound[i]=="Ti49"|| df_ionomic$compound[i]=="Tl205" ){ df_ionomic$type_ion[i]="other" df_ionomic$type_ion_num[i]=4 }}```## Filter outlier and cleaning data### Verif outlier### Extraction of good results only```{r}df_ionomic=df_ionomic %>%filter(!plant_num%in%c(1087,1039,93,1027)) %>%filter(!compound%in%c("Al27","Si28","Ag107","Pb208","Mo98","Ti49","Sb121"))```::: callout-important## I delet 93, 1027, 1039 and 1087:::::: callout-warning## I not analyse Al, Si, Pb, Ag, Ti and S because the results are not interesting or the variability is too higher:::```{r}# Exportation of the resultsdf_ionomic_export<-apply(df_ionomic,2,as.character)write.csv(as.data.frame(df_ionomic_export),row.names = F,here::here("data/iono/output/ionomic.csv"))write.csv(as.data.frame(df_ionomic),row.names = F,here::here("data/iono/output/ionomic_with_na.csv"))```