During April-May of 2021, we grew 7 DUF mutant lines on 1/2 MS plates with no salt/salt. We imaged the plates every other day from April 26 through May 4. Then, we traced the root structures using the Smart Root plugin on ImageJ. This is an analysis for the main root lengths, lateral root lengths, and total root size.

Uploading the data

getwd()
## [1] "C:/Users/J Lab/Desktop/RSA_analysis"
setwd("C:/Users/J Lab/Desktop/RSA_analysis/")
list.files()
##  [1] "20211202_RSA_analysis_Set2A.nb.html"             
##  [2] "20211202_RSA_analysis_Set2A.Rmd"                 
##  [3] "20211213_RSA_analysis.nb.html"                   
##  [4] "20211213_RSA_analysis.Rmd"                       
##  [5] "20220114_RSA_analysis.nb.html"                   
##  [6] "20220114_RSA_analysis.Rmd"                       
##  [7] "20220114_RSA_set1_analysis.nb.html"              
##  [8] "20220114_RSA_set1_analysis.Rmd"                  
##  [9] "20220121_RSA_analysis_set2.nb.html"              
## [10] "20220121_RSA_analysis_set2.Rmd"                  
## [11] "20220121_RSA_set1_analysis.nb.html"              
## [12] "20220121_RSA_set1_analysis.Rmd"                  
## [13] "20220124_RSA_set1_analysis.nb.html"              
## [14] "20220124_RSA_set1_analysis.Rmd"                  
## [15] "20220125_RSA_analysis_set2.nb.html"              
## [16] "20220125_RSA_analysis_set2.Rmd"                  
## [17] "20220125_RSA_set1_analysis.nb.html"              
## [18] "20220125_RSA_set1_analysis.Rmd"                  
## [19] "20220126_RSA_analysis_set2.nb.html"              
## [20] "20220126_RSA_analysis_set2.Rmd"                  
## [21] "20220126_RSA_set1_analysis.nb.html"              
## [22] "20220126_RSA_set1_analysis.Rmd"                  
## [23] "20220128_RSA_analysis_set2.nb.html"              
## [24] "20220128_RSA_analysis_set2.Rmd"                  
## [25] "20220128_RSA_set1_analysis.nb.html"              
## [26] "20220128_RSA_set1_analysis.Rmd"                  
## [27] "20220201_RSA_set1_analysis.nb.html"              
## [28] "20220201_RSA_set1_analysis.Rmd"                  
## [29] "20220202_RSA_set1_analysis.nb.html"              
## [30] "20220202_RSA_set1_analysis.Rmd"                  
## [31] "20220203_RSA_set1_analysis.nb.html"              
## [32] "20220203_RSA_set1_analysis.Rmd"                  
## [33] "20220204_RSA_analysis_set2.nb.html"              
## [34] "20220204_RSA_analysis_set2.Rmd"                  
## [35] "20220204_RSA_set1_analysis.nb.html"              
## [36] "20220204_RSA_set1_analysis.Rmd"                  
## [37] "20220207_RSA_analysis_set2.nb.html"              
## [38] "20220207_RSA_analysis_set2.Rmd"                  
## [39] "20220207_RSA_set1_analysis.nb.html"              
## [40] "20220207_RSA_set1_analysis.Rmd"                  
## [41] "20220208_RSA_set1_analysis.nb.html"              
## [42] "20220208_RSA_set1_analysis.Rmd"                  
## [43] "20220209_RSA_analysis_set2.nb.html"              
## [44] "20220209_RSA_analysis_set2.Rmd"                  
## [45] "20220209_RSA_set1_analysis.nb.html"              
## [46] "20220209_RSA_set1_analysis.Rmd"                  
## [47] "20220214_RSA_set1_analysis.nb.html"              
## [48] "20220214_RSA_set1_analysis.Rmd"                  
## [49] "20220215_RSA_set1_analysis.nb.html"              
## [50] "20220215_RSA_set1_analysis.Rmd"                  
## [51] "20220217_RSA_analysis_set2.nb.html"              
## [52] "20220217_RSA_analysis_set2.Rmd"                  
## [53] "20220217_RSA_set1_analysis.nb.html"              
## [54] "20220217_RSA_set1_analysis.Rmd"                  
## [55] "20220221_RSA_analysis_set2.nb.html"              
## [56] "20220221_RSA_analysis_set2.Rmd"                  
## [57] "20220221_RSA_set1_analysis.html"                 
## [58] "20220221_RSA_set1_analysis.nb.html"              
## [59] "20220221_RSA_set1_analysis.Rmd"                  
## [60] "20220311_RSA_analysis_set2.Rmd"                  
## [61] "20220311_RSA_set1_analysis.Rmd"                  
## [62] "20220316_RSA_analysis_set2.nb.html"              
## [63] "20220316_RSA_analysis_set2.Rmd"                  
## [64] "20220316_RSA_analysis_set2_files"                
## [65] "20220316_RSA_set1_analysis.html"                 
## [66] "20220316_RSA_set1_analysis.Rmd"                  
## [67] "AT salt stress images set 1_HS_20211202_redo.csv"
## [68] "AT salt stress images set 2a.csv"                
## [69] "AT salt stress images set 2b fixed.csv"          
## [70] "AT salt stress images set 2b.csv"                
## [71] "AT_salt_stress_set1_again.csv"                   
## [72] "AT_salt_stress_set1_day5.csv"                    
## [73] "AT_salt_stress_set1_otherdays.csv"               
## [74] "MR_GR_scatter.jpg"                               
## [75] "MR_GRset_errorplot.jpg"                          
## [76] "MR_STIset1_errorplot.jpg"                        
## [77] "MR_STIset2_errorplot.jpg"                        
## [78] "relative_GR.csv"                                 
## [79] "root_names.csv"                                  
## [80] "root_names_set_2.csv"                            
## [81] "RSA_MRL_lgraph.pdf"                              
## [82] "RSA_set1_redo_20220131.nb.html"                  
## [83] "RSA_set1_redo_20220131.Rmd"                      
## [84] "RSA_set2_MRLd4.pdf"                              
## [85] "RSA_set2_MRLd8.pdf"                              
## [86] "rsconnect"
RSA <- read.csv("AT salt stress images set 2a.csv")
RSA1 <- read.csv("AT salt stress images set 2b fixed.csv")
# READ another files in as RSA1
RSA <- rbind(RSA, RSA1)
RSA
RSA$info <- strsplit(RSA$image, "_")
RSA$info[1]
## [[1]]
## [1] "20210428"  "At"        "otherDUFs" "001.rsml"

Let’s isolate date into a separate column:

dim(RSA)
## [1] 1909   22
RSA$info[1]
## [[1]]
## [1] "20210428"  "At"        "otherDUFs" "001.rsml"
RSA$info[[1200]][1]
## [1] "20210504"
RSA$info[[1]][2]
## [1] "At"
RSA$date <- 0

for(i in 1:nrow(RSA)){
  RSA$date[i] <- RSA$info[[i]][1]
}

RSA

Now let’s transform it to DAYS after stress / treatment:

unique(RSA$date)
## [1] "20210428" "20210430" "20210504" "20210426"

Now - we need to change so that: “20210426” >> d0 “20210428” >> d2 “20210430” >> d4 “20210504” >> d8

RSA$info <- RSA$date
RSA$date <- gsub("20210426", "0", RSA$date)
RSA$date <- gsub("20210428", "2", RSA$date)
RSA$date <- gsub("20210430", "4", RSA$date)
RSA$date <- gsub("20210504", "8", RSA$date)
RSA

Calculating MR and LR specific files

subsetting between main roots and lateral roots

RSA_MR <- subset(RSA, RSA$root_order == 0)
RSA_LR <- subset(RSA, RSA$root_order != 0)
dim(RSA_MR)
## [1] 1094   23

subsetting between MR with and without LR

#subsetting MR between ones with lateral roots and without
RSA_MR_noLR <- subset(RSA_MR, RSA_MR$n_child == 0)
RSA_MR_LR <- subset(RSA_MR, RSA_MR$n_child != 0)

Match MR that HAVE LR with the belonging LRs

match the MR “root id” with the LR “parent ID” - let’s try it manually…

RSA_MR_LR$root[1]
## [1] " da6d5af6-56c2-4914-afcb-f724bfc607e4"
RSA_LR$parent[1]
## [1] " da6d5af6-56c2-4914-afcb-f724bfc607e4"
RSA_LR$parent[2]
## [1] " c6131aba-ff80-4804-82f7-4c049c35a14f"

now let’s automate it:

temp <- subset(RSA_LR, RSA_LR$parent == RSA_MR_LR$root[200])
temp <- subset(temp, temp$date == RSA_MR_LR$date[200])
temp

Let’s calculate the TOTAL LR length and LR number

LRL <- sum(temp$length)
temp$LRno <- 1
sum(temp$LRno)
## [1] 5
LRL
## [1] 0.378587
dim(temp)
## [1]  5 24
LRno <- dim(temp)[1]
LRno
## [1] 5

Now - let’s add these numbers to MR with LR file:

RSA_MR_LR$LRL <- 0
RSA_MR_LR$LRno <- 0
RSA_MR_LR

add the values to the appropriate columns:

RSA_MR_LR$LRL[1] <- LRL
RSA_MR_LR$LRno[1] <- LRno
RSA_MR_LR

LOOP IT!

for(i in 1:nrow(RSA_MR_LR)){
  temp <- subset(RSA_LR, RSA_LR$parent == RSA_MR_LR$root[i])
  temp <- subset(temp, temp$date == RSA_MR_LR$date[i])
  RSA_MR_LR$LRL[i]  <- sum(temp$length)
  RSA_MR_LR$LRno[i]  <- dim(temp)[1]
}

RSA_MR_LR

Let’s get ONLY the columns that we like:

colnames(RSA_MR_LR)
##  [1] "image"                 "root_name"             "root"                 
##  [4] "length"                "vector_length"         "surface"              
##  [7] "volume"                "direction"             "diameter"             
## [10] "root_order"            "root_ontology"         "parent_name"          
## [13] "parent"                "insertion_position"    "insertion_angle"      
## [16] "n_child"               "child_density"         "first_child"          
## [19] "insertion_first_child" "last_child"            "insertion_last_child" 
## [22] "info"                  "date"                  "LRL"                  
## [25] "LRno"
RSA_MR_LR2 <- RSA_MR_LR[,c(1:2,4,19,21,23:25)]
RSA_MR_LR2

Let’s fuse it with MR data with noLR:

RSA_MR_noLR$LRL <- 0
RSA_MR_noLR$LRno <- 0
RSA_MR_noLR2 <- RSA_MR_noLR[,c(1:2,4,19,21,23:25)]
RSA_MR_noLR2$insertion_first_child <- 0
RSA_MR_noLR2$insertion_last_child <- 0
RSA_MR_noLR2

Let’s fuse MR with LR and noLR files together:

RSA_MR <- rbind(RSA_MR_noLR2, RSA_MR_LR2)
dim(RSA_MR_noLR2)
## [1] 871   8
dim(RSA_MR_LR2)
## [1] 223   8
dim(RSA_MR)
## [1] 1094    8
RSA_MR

Let’s clean the entire table up - once again:

RSA_MR$insertion_first_child <- as.numeric(as.character(RSA_MR$insertion_first_child))
RSA_MR$insertion_last_child <- as.numeric(as.character(RSA_MR$insertion_last_child))

colnames(RSA_MR)[3] <- "MRL"
colnames(RSA_MR)[6] <- "Day"
RSA_MR$Branched <- RSA_MR$insertion_last_child - RSA_MR$insertion_first_child
RSA_MR$Basal <- RSA_MR$MRL - RSA_MR$insertion_last_child
RSA_MR$Apical <- RSA_MR$insertion_first_child
RSA_MR

Let’s clean it up again:

RSA_MR2 <- RSA_MR[,c(1,6,2:3,7:11)]
RSA_MR2

Last thing to calculate - Total Root Size:

RSA_MR2$TRS <- RSA_MR2$MRL + RSA_MR2$LRL
RSA_MR2

Now - let’s decode the plant information:

RSA_MR2$info <- strsplit(RSA_MR2$root_name, "_")
RSA_MR2$info[1]
## [[1]]
## [1] " Pl8" "p.4"  "C75"  "GC"
RSA_MR2$plate <- "NA"
RSA_MR2$plant <- "NA"
RSA_MR2$treatment <- "NA"
RSA_MR2$genotype <- "NA"
RSA_MR2

Loop it to replace NA

for(i in 1:nrow(RSA_MR2)){
   RSA_MR2$plate[i] <- RSA_MR2$info[[i]][1]
   RSA_MR2$plant[i] <- RSA_MR2$info[[i]][2]
   RSA_MR2$treatment[i] <- RSA_MR2$info[[i]][3]
   RSA_MR2$genotype[i] <- RSA_MR2$info[[i]][4]
}
RSA_MR2

Let’s check the format of all our plants:

unique(RSA_MR2$genotype)
## [1] "GC" "G7" "G6" "G5" "G2" "G1" "G4" "G3" NA
unique(RSA_MR2$plate)
##  [1] " Pl8"  " Pl7"  " Pl22" " Pl18" " Pl15" " Pl12" " Pl20" " Pl21" " Pl3" 
## [10] " Pl11" " Pl5"  " Pl6"  " Pl19" " Pl13" " Pl16" " Pl23" " Pl4"  " Pl17"
## [19] " Pl14" " Pl2"  " Pl24" " Pl10" " Pl1"  " Pl9"  " root"
unique(RSA_MR2$plant)
## [1] "p.4" "p.1" "P.4" "P.3" "P.2" "P.1" "p.3" "p.2" "2"
unique(RSA_MR2$treatment)
## [1] "C75"  "C125" "C0"   NA
temp2 <- subset(RSA_MR2, RSA_MR2$plate == " root")
temp2

Let’s remove the Root_2 from the file:

RSA_MR2 <- subset(RSA_MR2, RSA_MR2$root_name != " root_2")
unique(RSA_MR2$genotype)
## [1] "GC" "G7" "G6" "G5" "G2" "G1" "G4" "G3"
unique(RSA_MR2$plate)
##  [1] " Pl8"  " Pl7"  " Pl22" " Pl18" " Pl15" " Pl12" " Pl20" " Pl21" " Pl3" 
## [10] " Pl11" " Pl5"  " Pl6"  " Pl19" " Pl13" " Pl16" " Pl23" " Pl4"  " Pl17"
## [19] " Pl14" " Pl2"  " Pl24" " Pl10" " Pl1"  " Pl9"
unique(RSA_MR2$plant)
## [1] "p.4" "p.1" "P.4" "P.3" "P.2" "P.1" "p.3" "p.2"
unique(RSA_MR2$treatment)
## [1] "C75"  "C125" "C0"

to do - change genotype names + treatment names

RSA_MR2$plate <- gsub("p", "P", RSA_MR2$plate)
RSA_MR2$plate <- gsub("Pl", "", RSA_MR2$plate)
RSA_MR2$plate <- as.numeric(as.character(RSA_MR2$plate))


# same for genotype
RSA_MR2$genotype <- gsub("GC", "Col-0", RSA_MR2$genotype)
RSA_MR2$genotype <- gsub("G1", "170-3F", RSA_MR2$genotype)
RSA_MR2$genotype <- gsub("G2", "170-4F", RSA_MR2$genotype)
RSA_MR2$genotype <- gsub("G3", "170-5A", RSA_MR2$genotype)
RSA_MR2$genotype <- gsub("G4", "190-2B", RSA_MR2$genotype)
RSA_MR2$genotype <- gsub("G5", "200-1A", RSA_MR2$genotype)
RSA_MR2$genotype <- gsub("G6", "200-2B", RSA_MR2$genotype)
RSA_MR2$genotype <- gsub("G7", "200-3B", RSA_MR2$genotype)
# same for treatment
RSA_MR2$treatment <- gsub("C", "", RSA_MR2$treatment)
RSA_MR2$treatment <- as.numeric(as.character(RSA_MR2$treatment))
#same for plant
RSA_MR2$plant <- gsub("p.", "P.", RSA_MR2$plant)
RSA_MR2$plant <- gsub("P.", "", RSA_MR2$plant)
#check
unique(RSA_MR2$genotype)
## [1] "Col-0"  "200-3B" "200-2B" "200-1A" "170-4F" "170-3F" "190-2B" "170-5A"
unique(RSA_MR2$plate)
##  [1]  8  7 22 18 15 12 20 21  3 11  5  6 19 13 16 23  4 17 14  2 24 10  1  9
unique(RSA_MR2$plant)
## [1] "4" "1" "3" "2"
unique(RSA_MR2$treatment)
## [1]  75 125   0
# convert day to numeric
RSA_MR2$Day <- as.numeric(as.character(RSA_MR2$Day))

analyzing the data - comparing the genotypes

RSA_MR2$TRS <- as.numeric(as.factor(RSA_MR2$TRS))
day4 <- subset(RSA_MR2, RSA_MR2$Day == "4")
day4
library(ggplot2)
library(ggpubr)
TRS <- ggplot(day4, aes(x = genotype, y = TRS))
TRS <- TRS + geom_boxplot() + theme(axis.text.x = element_text(angle = 90))
TRS <- TRS + facet_grid(~ treatment)
TRS

Let’s order treatment according to severity of stress

day4$treatment <- factor(day4$treatment, level = c(0, 75, 125))
day4$genotype <- factor(day4$genotype, level = c("Col-0", "170-3F", "170-4F", "170-5A", "190-2B", "200-1A", "200-2B", "200-3B"))
day4
TRS <- ggplot(day4, aes(x = genotype, y = TRS, fill = genotype))
TRS <- TRS + geom_boxplot() + theme(axis.text.x = element_text(angle = 90)) + rremove("legend")
TRS <- TRS + facet_grid(~ treatment)
TRS <- TRS + ggtitle("Days of Treatment - 4")
TRS

day2 <- subset(RSA_MR2, RSA_MR2$Day == "2")
day2$genotype <- factor(day2$genotype, level = c("Col-0", "170-3F", "170-4F", "170-5A", "190-2B", "200-1A", "200-2B", "200-3B"))

TRS_2 <- ggplot(day2, aes(x = genotype, y = TRS, fill = genotype))
TRS_2 <- TRS_2 + geom_boxplot() + theme(axis.text.x = element_text(angle = 90)) + rremove("legend")
TRS_2 <- TRS_2 + facet_grid(~ treatment)
TRS_2 <- TRS_2 + ggtitle("Days of Treatment - 2")
TRS_2

day0 <- subset(RSA_MR2, RSA_MR2$Day == "0")
day0$genotype <- factor(day0$genotype, level = c("Col-0", "170-3F", "170-4F", "170-5A", "190-2B", "200-1A", "200-2B", "200-3B"))

TRS_0 <- ggplot(day0, aes(x = genotype, y = TRS, fill = genotype))
TRS_0 <- TRS_0 + geom_boxplot() + theme(axis.text.x = element_text(angle = 90)) + rremove("legend")
TRS_0 <- TRS_0 + facet_grid(~ treatment)
TRS_0 <- TRS_0 + ggtitle("Days of Treatment - 0")
TRS_0

day8 <- subset(RSA_MR2, RSA_MR2$Day == "8")
day8$genotype <- factor(day8$genotype, level = c("Col-0", "170-3F", "170-4F", "170-5A", "190-2B", "200-1A", "200-2B", "200-3B"))

TRS_8 <- ggplot(day8, aes(x = genotype, y = TRS, fill = genotype))
TRS_8 <- TRS_8 + geom_boxplot() + theme(axis.text.x = element_text(angle = 90)) + rremove("legend")
TRS_8 <- TRS_8 + facet_grid(~ treatment)
TRS_8 <- TRS_8 + ggtitle("Days of Treatment - 8")
TRS_8

MRL_0 <- ggplot(day0, aes(x = genotype, y = MRL, fill = genotype))
MRL_0 <- MRL_0 + geom_boxplot() + theme(axis.text.x = element_text(angle = 90)) + rremove("legend")
MRL_0 <- MRL_0 + facet_grid(~ treatment)
MRL_0 <- MRL_0 + ggtitle("Days of Treatment - 0")
MRL_0

MRL_2 <- ggplot(day2, aes(x = genotype, y = MRL, fill = genotype))
MRL_2 <- MRL_2 + geom_boxplot() + theme(axis.text.x = element_text(angle = 90)) + rremove("legend")
MRL_2 <- MRL_2 + facet_grid(~ treatment)
MRL_2 <- MRL_2 + ggtitle("Days of Treatment - 2")
MRL_2

MRL_4 <- ggplot(day4, aes(x = genotype, y = MRL, fill = genotype))
MRL_4 <- MRL_4 + geom_boxplot() + theme(axis.text.x = element_text(angle = 90)) + rremove("legend")
MRL_4 <- MRL_4 + facet_grid(~ treatment)
MRL_4 <- MRL_4 + ggtitle("Days of Treatment - 4")
MRL_4

MRL_8 <- ggplot(day8, aes(x = genotype, y = MRL, fill = genotype))
MRL_8 <- MRL_8 + geom_boxplot() + theme(axis.text.x = element_text(angle = 90)) + rremove("legend")
MRL_8 <- MRL_8 + facet_grid(~ treatment)
MRL_8 <- MRL_8 + ggtitle("Days of Treatment - 8")
MRL_8

LRL_4 <- ggplot(day4, aes(x = genotype, y = LRL, fill = genotype))
LRL_4 <- LRL_4 + geom_boxplot() + theme(axis.text.x = element_text(angle = 90)) + rremove("legend")
LRL_4 <- LRL_4 + facet_grid(~ treatment)
LRL_4 <- LRL_4 + ggtitle("Days of Treatment - 4")
LRL_4

LRL_8 <- ggplot(day8, aes(x = genotype, y = LRL, fill = genotype))
LRL_8 <- LRL_8 + geom_boxplot() + theme(axis.text.x = element_text(angle = 90)) + rremove("legend")
LRL_8 <- LRL_8 + facet_grid(~ treatment)
LRL_8 <- LRL_8 + ggtitle("Days of Treatment - 8")
LRL_8

Apical_4 <- ggplot(day4, aes(x = genotype, y = Apical, fill = genotype))
Apical_4 <- Apical_4 + geom_boxplot() + theme(axis.text.x = element_text(angle = 90)) + rremove("legend")
Apical_4 <- Apical_4 + facet_grid(~ treatment)
Apical_4 <- Apical_4 + ggtitle("Days of Treatment - 4")
Apical_4

Apical_8 <- ggplot(day8, aes(x = genotype, y = Apical, fill = genotype))
Apical_8 <- Apical_8 + geom_boxplot() + theme(axis.text.x = element_text(angle = 90)) + rremove("legend")
Apical_8 <- Apical_8 + facet_grid(~ treatment)
Apical_8 <- Apical_8 + ggtitle("Days of Treatment - 8")
Apical_8

Basal_4 <- ggplot(day4, aes(x = genotype, y = Basal, fill = genotype))
Basal_4 <- Basal_4 + geom_boxplot() + theme(axis.text.x = element_text(angle = 90)) + rremove("legend")
Basal_4 <- Basal_4 + facet_grid(~ treatment)
Basal_4 <- Basal_4 + ggtitle("Days of Treatment - 4")
Basal_4

Basal_8 <- ggplot(day8, aes(x = genotype, y = Basal, fill = genotype))
Basal_8 <- Basal_8 + geom_boxplot() + theme(axis.text.x = element_text(angle = 90)) + rremove("legend")
Basal_8 <- Basal_8 + facet_grid(~ treatment)
Basal_8 <- Basal_8 + ggtitle("Days of Treatment - 8")
Basal_8

Branched_4 <- ggplot(day4, aes(x = genotype, y = Branched, fill = genotype))
Branched_4 <- Branched_4 + geom_boxplot() + theme(axis.text.x = element_text(angle = 90)) + rremove("legend")
Branched_4 <- Branched_4 + facet_grid(~ treatment)
Branched_4 <- Branched_4 + ggtitle("Days of Treatment - 4")
Branched_4

Branched_8 <- ggplot(day8, aes(x = genotype, y = Branched, fill = genotype))
Branched_8 <- Branched_8 + geom_boxplot() + theme(axis.text.x = element_text(angle = 90)) + rremove("legend")
Branched_8 <- Branched_8 + facet_grid(~ treatment)
Branched_8 <- Branched_8 + ggtitle("Days of Treatment - 8")
Branched_8

Let’s do a fancy plot:

library(ggpubr)
TRS_d4_errorplot <- ggerrorplot(day4, y="TRS", x="genotype", fill="genotype", ncol = 3, facet.by = "treatment",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Total Root Size (cm)", main = "Days of Treatment - 4") + theme(axis.text.x = element_text(angle = 90))
TRS_d4_errorplot <- TRS_d4_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref.group = "Col-0", label = "p.signif")
TRS_d4_errorplot

TRS_d0_errorplot <- ggerrorplot(day0, y="TRS", x="genotype", fill="genotype", ncol = 3, facet.by = "treatment",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Total Root Size (cm)", main = "Days of Treatment - 0") + theme(axis.text.x = element_text(angle = 90))
TRS_d0_errorplot <- TRS_d0_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "Col-0", label = "p.signif")
TRS_d0_errorplot

TRS_d2_errorplot <- ggerrorplot(day2, y="TRS", x="genotype", fill="genotype", ncol = 3, facet.by = "treatment",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Total Root Size (cm)", main = "Days of Treatment - 2") + theme(axis.text.x = element_text(angle = 90))
TRS_d2_errorplot <- TRS_d2_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "Col-0", label = "p.signif")
TRS_d2_errorplot

TRS_d8_errorplot <- ggerrorplot(day8, y="TRS", x="genotype", fill="genotype", ncol = 3, facet.by = "treatment",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Total Root Size (cm)", main = "Days of Treatment 8") + theme(axis.text.x = element_text(angle = 90))
TRS_d8_errorplot <- TRS_d8_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "Col-0", label = "p.signif")
TRS_d8_errorplot

#Let's make error plots for lateral root size and main root length:

LRL_d0_errorplot <- ggerrorplot(day0, y="LRL", x="genotype", fill="genotype", ncol = 3, facet.by = "treatment",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Lateral Root Length (cm)", main = "Days of Treatment - 0") + theme(axis.text.x = element_text(angle = 90))
LRL_d0_errorplot <- LRL_d0_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "Col-0", label = "p.signif")
LRL_d0_errorplot

LRL_d2_errorplot <- ggerrorplot(day2, y="LRL", x="genotype", fill="genotype", ncol = 3, facet.by = "treatment",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Lateral Root Length (cm)", main = "Days of Treatment - 2") + theme(axis.text.x = element_text(angle = 90))
LRL_d2_errorplot <- LRL_d2_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "Col-0", label = "p.signif")
LRL_d2_errorplot

LRL_d4_errorplot <- ggerrorplot(day4, y="LRL", x="genotype", fill="genotype", ncol = 3, facet.by = "treatment",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Lateral Root Length (cm)", main = "Days of Treatment - 4") + theme(axis.text.x = element_text(angle = 90))
LRL_d4_errorplot <- LRL_d4_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "Col-0", label = "p.signif")
LRL_d4_errorplot

LRL_d8_errorplot <- ggerrorplot(day8, y="LRL", x="genotype", fill="genotype", ncol = 3, facet.by = "treatment",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Lateral Root Length (cm)", main = "Days of Treatment - 8") + theme(axis.text.x = element_text(angle = 90))
LRL_d8_errorplot <- LRL_d8_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "Col-0", label = "p.signif")
LRL_d8_errorplot

MRL_d0_errorplot <- ggerrorplot(day0, y="MRL", x="genotype", fill="genotype", ncol = 3, facet.by = "treatment",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Main Root Length (cm)", main = "Days of Treatment - 0") + theme(axis.text.x = element_text(angle = 90))
MRL_d0_errorplot <- MRL_d0_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "Col-0", label = "p.signif")
MRL_d0_errorplot

MRL_d2_errorplot <- ggerrorplot(day2, y="MRL", x="genotype", fill="genotype", ncol = 3, facet.by = "treatment",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Main Root Length (cm)", main = "Day 2") + theme(axis.text.x = element_text(angle = 90))
MRL_d2_errorplot <- MRL_d2_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "Col-0", label = "p.signif")
MRL_d2_errorplot

MRL_d4_errorplot <- ggerrorplot(day4, y="MRL", x="genotype", fill="genotype", ncol = 3, facet.by = "treatment",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Main Root Length (cm)", main = "Days of Treatment - 4") + theme(axis.text.x = element_text(angle = 90))
MRL_d4_errorplot <- MRL_d4_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "Col-0", label = "p.signif")
MRL_d4_errorplot

MRL_d8_errorplot <- ggerrorplot(day8, y="MRL", x="genotype", fill="genotype", ncol = 3, facet.by = "treatment",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Main Root Length (cm)", main = "Days of Treatment - 8") + theme(axis.text.x = element_text(angle = 90))
MRL_d8_errorplot <- MRL_d8_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "Col-0", label = "p.signif")
MRL_d8_errorplot

#Basal distance
Basal_d4_errorplot <- ggerrorplot(day4, y="Basal", x="genotype", fill="genotype", ncol = 3, facet.by = "treatment",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Basal Distance (cm)", main = "Days of Treatment - 4") + theme(axis.text.x = element_text(angle = 90))
Basal_d4_errorplot <- Basal_d4_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "Col-0", label = "p.signif")
Basal_d4_errorplot

Basal_d8_errorplot <- ggerrorplot(day8, y="Basal", x="genotype", fill="genotype", ncol = 3, facet.by = "treatment",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab= "Basal Distance (cm)", main = "Days of Treatment - 8") + theme(axis.text.x = element_text(angle = 90))
Basal_d8_errorplot <- Basal_d8_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "Col-0", label = "p.signif")
Basal_d8_errorplot

#Apical distance
Apical_d4_errorplot <- ggerrorplot(day4, y="Apical", x="genotype", fill="genotype", ncol = 3, facet.by = "treatment",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Apical Distance (cm)", main = "Days of Treatment - 4") + theme(axis.text.x = element_text(angle = 90))
Apical_d4_errorplot <- Apical_d4_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "Col-0", label = "p.signif")
Apical_d4_errorplot

Apical_d8_errorplot <- ggerrorplot(day8, y="Apical", x="genotype", fill="genotype", ncol = 3, facet.by = "treatment",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab= "Apical Distance (cm)", main = "Days of Treatment - 8") + theme(axis.text.x = element_text(angle = 90))
Apical_d8_errorplot <- Apical_d8_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "Col-0", label = "p.signif")
Apical_d8_errorplot

#Branched distance
Branched_d4_errorplot <- ggerrorplot(day4, y="Branched", x="genotype", fill="genotype", ncol = 3, facet.by = "treatment",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Branched Distance (cm)", main = "Days of Treatment - 4") + theme(axis.text.x = element_text(angle = 90))
Branched_d4_errorplot <- Branched_d4_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "Col-0", label = "p.signif")
Branched_d4_errorplot

Branched_d8_errorplot <- ggerrorplot(day8, y="Branched", x="genotype", fill="genotype", ncol = 3, facet.by = "treatment",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab= "Branched Distance (cm)", main = "Days of Treatment - 8") + theme(axis.text.x = element_text(angle = 90))
Branched_d8_errorplot <- Branched_d8_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "Col-0", label = "p.signif")
Branched_d8_errorplot

#checking data frame for genotypes that are missing in above plots (day 0, 75mM, 170-3F, 200-1A, 190-2B)
# all_75 <- subset(RSA_MR2, RSA_MR2$treatment == "75")
# all_75
# check_1703F <- subset(all_75, all_75$genotype == "170-3F")
# check_1703F
#I am going to look at these images and see if the individuals are not yet germinated on day 0
#note: they have; rsml files are missing. I am retracing on 12/23/21 and will continue analysis after
#As of 1/14/2022 the missing data has been added to the files and the file rerun; there is nothing missing now

Let’s start plotting: first, a line graph of total root size over time

unique(RSA_MR2$treatment)
## [1]  75 125   0
RSA_MR2$treatment <- as.factor(as.numeric(RSA_MR2$treatment))
RSA_MR2$treatment <- factor(RSA_MR2$treatment, levels = c("0", "75", "125"))
RSA_MR2
TRS_over_time <- ggplot(RSA_MR2, aes(x = Day, y = TRS, group = root_name, color = treatment)) + theme_classic()
TRS_over_time <- TRS_over_time + geom_line(alpha=0.1)
TRS_over_time<-TRS_over_time + stat_summary(fun=mean, aes(group= treatment),size=0.8, geom="line", linetype="dashed")
TRS_over_time <- TRS_over_time + scale_color_manual(labels=c("0 mM", "75 mM", "125 mM"), values=c("limegreen", "red4", "midnightblue"))
TRS_over_time <- TRS_over_time + xlab("Day of Treatment") + ylab("Total Root Length (cm)") + ggtitle("Total Root Size Over Time")
TRS_over_time

facet by genotype

TRS_by_geno <- ggplot(RSA_MR2, aes(x = Day, y = TRS, group = root_name, color = treatment)) + theme_classic()
TRS_by_geno <- TRS_by_geno + geom_line(alpha=0.1) + facet_wrap(~genotype)
TRS_by_geno<-TRS_by_geno + stat_summary(fun=mean, aes(group= treatment),size=0.8, geom="line", linetype="dashed")
TRS_by_geno <- TRS_by_geno + scale_color_manual(labels=c("0 mM", "75 mM", "125 mM"), values=c("limegreen", "red4", "midnightblue"))
TRS_by_geno <- TRS_by_geno + xlab("Day of Treatment") + ylab("Total Root Length (cm)") + ggtitle("Total Root Size Over Time")
TRS_by_geno

MRL_over_time <- ggplot(RSA_MR2, aes(x = Day, y = MRL, group = root_name, color = treatment)) + theme_classic()
MRL_over_time <- MRL_over_time + geom_line(alpha=0.1)
MRL_over_time<-MRL_over_time + stat_summary(fun=mean, aes(group= treatment),size=0.8, geom="line", linetype="dashed")
MRL_over_time <- MRL_over_time + scale_color_manual(labels=c("0 mM", "75 mM", "125 mM"), values=c("limegreen", "red4", "midnightblue"))
MRL_over_time <- MRL_over_time + xlab("Day of Treatment") + ylab("Main Root Length (cm)") + ggtitle("Main Root Length Over Time")
MRL_over_time

MRL_by_geno <- ggplot(RSA_MR2, aes(x = Day, y = MRL, group = root_name, color = treatment)) + theme_classic()
MRL_by_geno <- MRL_by_geno + geom_line(alpha=0.1) + facet_wrap(~genotype)
MRL_by_geno<-MRL_by_geno + stat_summary(fun=mean, aes(group= treatment),size=0.8, geom="line", linetype="dashed")
MRL_by_geno <- MRL_by_geno + scale_color_manual(labels=c("0 mM", "75 mM", "125 mM"), values=c("limegreen", "red4", "midnightblue"))
MRL_by_geno <- MRL_by_geno + xlab("Day of Treatment") + ylab("Main Root Length (cm)") + ggtitle("Main Root Length Over Time")
MRL_by_geno

Basal_over_time <- ggplot(RSA_MR2, aes(x = Day, y = Basal, group = root_name, color = treatment)) + theme_classic()
Basal_over_time <- Basal_over_time + geom_line(alpha=0.1)
Basal_over_time<-Basal_over_time + stat_summary(fun=mean, aes(group= treatment),size=0.8, geom="line", linetype="dashed")
Basal_over_time <- Basal_over_time + scale_color_manual(labels=c("0 mM", "75 mM", "125 mM"), values=c("limegreen", "red4", "midnightblue"))
Basal_over_time <- Basal_over_time + xlab("Day of Treatment") + ggtitle("Basal Distance Over Time")
Basal_over_time

Basal_by_geno <- ggplot(RSA_MR2, aes(x = Day, y = Basal, group = root_name, color = treatment)) + theme_classic()
Basal_by_geno <- Basal_by_geno + geom_line(alpha=0.1) + facet_wrap(~genotype)
Basal_by_geno<-Basal_by_geno + stat_summary(fun=mean, aes(group= treatment),size=0.8, geom="line", linetype="dashed")
Basal_by_geno <- Basal_by_geno + scale_color_manual(labels=c("0 mM", "75 mM", "125 mM"), values=c("limegreen", "red4", "midnightblue"))
Basal_by_geno <- Basal_by_geno + xlab("Day of Treatment") + ylab("Basal Distance (cm)") + ggtitle("Basal Distance Over Time")
Basal_by_geno

Apical_over_time <- ggplot(RSA_MR2, aes(x = Day, y = Apical, group = root_name, color = treatment)) + theme_classic()
Apical_over_time <- Apical_over_time + geom_line(alpha=0.1)
Apical_over_time<-Apical_over_time + stat_summary(fun=mean, aes(group= treatment),size=0.8, geom="line", linetype="dashed")
Apical_over_time <- Apical_over_time + scale_color_manual(labels=c("0 mM", "75 mM", "125 mM"), values=c("limegreen", "red4", "midnightblue"))
Apical_over_time <- Apical_over_time + xlab("Day of Treatment") + ylab("Apical Distance (cm)") + ggtitle("Apical Distance Over Time")
Apical_over_time

Apical_by_geno <- ggplot(RSA_MR2, aes(x = Day, y = Apical, group = root_name, color = treatment)) + theme_classic()
Apical_by_geno <- Apical_by_geno + geom_line(alpha=0.1) + facet_wrap(~genotype)
Apical_by_geno<-Apical_by_geno + stat_summary(fun=mean, aes(group= treatment),size=0.8, geom="line", linetype="dashed")
Apical_by_geno <- Apical_by_geno + scale_color_manual(labels=c("0 mM", "75 mM", "125 mM"), values=c("limegreen", "red4", "midnightblue"))
Apical_by_geno <- Apical_by_geno + xlab("Day of Treatment") + ylab("Apical Distance (cm)") + ggtitle("Apical Distance Over Time")
Apical_by_geno

Branched_over_time <- ggplot(RSA_MR2, aes(x = Day, y = Branched, group = root_name, color = treatment)) + theme_classic()
Branched_over_time <- Branched_over_time + geom_line(alpha=0.1)
Branched_over_time<-Branched_over_time + stat_summary(fun=mean, aes(group= treatment),size=0.8, geom="line", linetype="dashed")
Branched_over_time <- Branched_over_time + scale_color_manual(labels=c("0 mM", "75 mM", "125 mM"), values=c("limegreen", "red4", "midnightblue"))
Branched_over_time <- Branched_over_time + xlab("Day of Treatment") + ylab("Branched Distance (cm)") + ggtitle("Branched Distance Over Time")
Branched_over_time

Branched_by_geno <- ggplot(RSA_MR2, aes(x = Day, y = Branched, group = root_name, color = treatment)) + theme_classic()
Branched_by_geno <- Branched_by_geno + geom_line(alpha=0.1) + facet_wrap(~genotype)
Branched_by_geno<-Branched_by_geno + stat_summary(fun=mean, aes(group= treatment),size=0.8, geom="line", linetype="dashed")
Branched_by_geno <- Branched_by_geno + scale_color_manual(labels=c("0 mM", "75 mM", "125 mM"), values=c("limegreen", "red4", "midnightblue"))
Branched_by_geno <- Branched_by_geno + xlab("Day of Treatment") + ylab("Branched Distance (cm)") + ggtitle("Branched Distance Over Time")
Branched_by_geno

Try making an error plot where each genotype is faceted by day, treatment on x axis

RSA_MR2
Col <- subset(RSA_MR2, RSA_MR2$genotype == "Col-0")
G1703F <- subset(RSA_MR2, RSA_MR2$genotype == "170-3F")
G1704F <- subset(RSA_MR2, RSA_MR2$genotype == "170-4F")
G1705A <- subset(RSA_MR2, RSA_MR2$genotype == "170-5A")
G1902B <- subset(RSA_MR2, RSA_MR2$genotype == "190-2B")
G2001A <- subset(RSA_MR2, RSA_MR2$genotype == "200-1A")
G2002B <- subset(RSA_MR2, RSA_MR2$genotype == "200-2B")
G2003B <- subset(RSA_MR2, RSA_MR2$genotype == "200-3B")
head(G1704F)

These plots use data subset by genotype. It has treatment on the x axis and TRS on the y axis, faceted by day

TRS_G1704F_errorplot <- ggerrorplot(G1704F, y="TRS", x="treatment", fill="treatment", ncol = 3, facet.by = "Day",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Total Root Size (cm)", main = "170-4F")
TRS_G1704F_errorplot <- TRS_G1704F_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "0", label = "p.signif")
TRS_G1704F_errorplot

TRS_Col_errorplot <- ggerrorplot(Col, y="TRS", x="treatment", fill="treatment", ncol = 3, facet.by = "Day",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Total Root Size (cm)", main = "Col-0")
TRS_Col_errorplot <- TRS_Col_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "0", label = "p.signif")
TRS_Col_errorplot

TRS_G1703F_errorplot <- ggerrorplot(G1703F, y="TRS", x="treatment", fill="treatment", ncol = 3, facet.by = "Day",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Total Root Size (cm)", main = "170-3F")
TRS_G1703F_errorplot <- TRS_G1703F_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "0", label = "p.signif")
TRS_G1703F_errorplot

TRS_G1705A_errorplot <- ggerrorplot(G1705A, y="TRS", x="treatment", fill="treatment", ncol = 3, facet.by = "Day",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Total Root Size (cm)", main = "170-5A")
TRS_G1705A_errorplot <- TRS_G1705A_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "0", label = "p.signif")
TRS_G1705A_errorplot

TRS_G1902B_errorplot <- ggerrorplot(G1902B, y="TRS", x="treatment", fill="treatment", ncol = 3, facet.by = "Day",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Total Root Size (cm)", main = "190-2B")
TRS_G1902B_errorplot <- TRS_G1902B_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "0", label = "p.signif")
TRS_G1902B_errorplot

TRS_G2001A_errorplot <- ggerrorplot(G2001A, y="TRS", x="treatment", fill="treatment", ncol = 3, facet.by = "Day",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Total Root Size (cm)", main = "200-1A")
TRS_G2001A_errorplot <- TRS_G2001A_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "0", label = "p.signif")
TRS_G2001A_errorplot

TRS_G2002B_errorplot <- ggerrorplot(G2002B, y="TRS", x="treatment", fill="treatment", ncol = 3, facet.by = "Day",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Total Root Size (cm)", main = "200-2B")
TRS_G2002B_errorplot <- TRS_G2002B_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "0", label = "p.signif")
TRS_G2002B_errorplot

TRS_G2003B_errorplot <- ggerrorplot(G2003B, y="TRS", x="treatment", fill="treatment", ncol = 3, facet.by = "Day",
                                desc_stat = "mean_sd", add="jitter", add.params = list(color = "darkgray"),
                                xlab="", ylab="Total Root Size (cm)", main = "200-3B")
TRS_G2003B_errorplot <- TRS_G2003B_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref = "0", label = "p.signif")
TRS_G2003B_errorplot

###Boxplots of basal, branched, and apex of plants with LRs

RSA_only_LR <- subset(RSA_MR2, RSA_MR2$LRno != 0)
RSA_only_LR
LR_length <- ggplot(RSA_only_LR, aes(x = Day, y = LRL, group = genotype, fill = genotype))
LR_length <- LR_length + geom_boxplot() + theme(axis.text.x = element_text(angle = 90))
LR_length <- LR_length + facet_grid(~ treatment)
LR_length <- LR_length + ggtitle("Lateral Root Lengths")
LR_length

#comparing each genotype to Col
RSA_MR2
length(unique(RSA_MR2$genotype))
## [1] 8
Col_data2 <- subset(RSA_MR2, RSA_MR2$genotype == "Col-0")
Col_data2
Col1 <- Col_data2
Col1$facet2 <- unique(RSA_MR2$genotype)[1]
Col2 <- Col_data2
Col2$facet2 <- unique(RSA_MR2$genotype)[2]
Col3 <- Col_data2
Col3$facet2 <- unique(RSA_MR2$genotype)[3]
Col4 <- Col_data2
Col4$facet2 <- unique(RSA_MR2$genotype)[4]
Col5 <- Col_data2
Col5$facet2 <- unique(RSA_MR2$genotype)[5]
Col6 <- Col_data2
Col6$facet2 <- unique(RSA_MR2$genotype)[6]
Col7 <- Col_data2
Col7$facet2 <- unique(RSA_MR2$genotype)[7]
Col8 <- Col_data2
Col8$facet2 <- unique(RSA_MR2$genotype)[8]

RSA_MR2$facet2 <- RSA_MR2$genotype 
RSA_comp2 <- rbind(RSA_MR2, Col1)
RSA_comp2 <- rbind(RSA_comp2, Col2)
RSA_comp2 <- rbind(RSA_comp2, Col3)
RSA_comp2 <- rbind(RSA_comp2, Col4)
RSA_comp2 <- rbind(RSA_comp2, Col5)
RSA_comp2 <- rbind(RSA_comp2, Col6)
RSA_comp2 <- rbind(RSA_comp2, Col7)
RSA_comp2 <- rbind(RSA_comp2, Col8)
unique(RSA_comp2$facet2)
## [1] "Col-0"  "200-3B" "200-2B" "200-1A" "170-4F" "170-3F" "190-2B" "170-5A"
RSA_comp2
RSA_comp2$treatment <- factor(RSA_comp2$treatment, levels = c("0", "75", "125"))
RSA_comp2$Day <- as.numeric(as.character(RSA_comp2$Day))
RSA_comp2 <- subset(RSA_comp2, RSA_comp2$facet2 != "Col-0")
unique(RSA_comp2$facet)
## [1] "200-3B" "200-2B" "200-1A" "170-4F" "170-3F" "190-2B" "170-5A"
RSA_comp2$Day <- as.factor(RSA_comp2$Day)
MRL_lgraph <- ggplot(data = RSA_comp2, aes(x = Day, y = MRL, group = root_name, color = genotype)) + theme_classic()
MRL_lgraph <- MRL_lgraph + geom_line(alpha = 0.1)
MRL_lgraph <- MRL_lgraph + facet_grid(facet2 ~ treatment)
MRL_lgraph <- MRL_lgraph + stat_summary(fun.data = mean_se, geom = "ribbon", linetype = 0, aes(group = genotype), alpha = 0.3) + stat_summary(fun = mean, aes(group = genotype), size = 0.7, geom = "line", linetype = "solid")
MRL_lgraph <- MRL_lgraph + stat_compare_means(aes(group = genotype), label = "p.signif", method = "t.test", hide.ns = F, label.y = 5)
MRL_lgraph <- MRL_lgraph + xlab("Day of Treatment") + ylab("Main Root Length (cm)") + rremove("legend")
MRL_lgraph

LRL_lgraph <- ggplot(data = RSA_comp2, aes(x = Day, y = LRL, group = root_name, color = genotype)) + theme_classic()
LRL_lgraph <- LRL_lgraph + geom_line(alpha = 0.1)
LRL_lgraph <- LRL_lgraph + facet_grid(facet2 ~ treatment)
LRL_lgraph <- LRL_lgraph + stat_summary(fun.data = mean_se, geom = "ribbon", linetype = 0, aes(group = genotype), alpha = 0.3) + stat_summary(fun = mean, aes(group = genotype), size = 0.7, geom = "line", linetype = "solid")
LRL_lgraph <- LRL_lgraph + stat_compare_means(aes(group = genotype), label = "p.signif", method = "t.test", hide.ns = F, label.y = 5)
LRL_lgraph <- LRL_lgraph + xlab("Day of Treatment") + ylab("Lateral Root Length (cm)") + rremove("legend")
LRL_lgraph

#TRS
TRS_lgraph <- ggplot(data = RSA_comp2, aes(x = Day, y = TRS, group = root_name, color = genotype)) + theme_classic()
TRS_lgraph <- TRS_lgraph + geom_line(alpha = 0.1)
TRS_lgraph <- TRS_lgraph + facet_grid(facet2 ~ treatment)
TRS_lgraph <- TRS_lgraph + stat_summary(fun.data = mean_se, geom = "ribbon", linetype = 0, aes(group = genotype), alpha = 0.3) + stat_summary(fun = mean, aes(group = genotype), size = 0.7, geom = "line", linetype = "solid")
TRS_lgraph <- TRS_lgraph + stat_compare_means(aes(group = genotype), label = "p.signif", method = "t.test", hide.ns = F, label.y = 5)
TRS_lgraph <- TRS_lgraph + xlab("Day of Treatment") + ylab("Total Root Size (cm)") + rremove("legend")
TRS_lgraph

#Basal distance
Basal_lgraph <- ggplot(data = RSA_comp2, aes(x = Day, y = Basal, group = root_name, color = genotype)) + theme_classic()
Basal_lgraph <- Basal_lgraph + geom_line(alpha = 0.1)
Basal_lgraph <- Basal_lgraph + facet_grid(facet2 ~ treatment)
Basal_lgraph <- Basal_lgraph + stat_summary(fun.data = mean_se, geom = "ribbon", linetype = 0, aes(group = genotype), alpha = 0.3) + stat_summary(fun = mean, aes(group = genotype), size = 0.7, geom = "line", linetype = "solid")
Basal_lgraph <- Basal_lgraph + stat_compare_means(aes(group = genotype), label = "p.signif", method = "t.test", hide.ns = F, label.y = 5)
Basal_lgraph <- Basal_lgraph + xlab("Day of Treatment") + ylab("Basal Distance (cm)") + rremove("legend")
Basal_lgraph

#Apical distance
Apical_lgraph <- ggplot(data = RSA_comp2, aes(x = Day, y = Apical, group = root_name, color = genotype)) + theme_classic()
Apical_lgraph <- Apical_lgraph + geom_line(alpha = 0.1)
Apical_lgraph <- Apical_lgraph + facet_grid(facet2 ~ treatment)
Apical_lgraph <- Apical_lgraph + stat_summary(fun.data = mean_se, geom = "ribbon", linetype = 0, aes(group = genotype), alpha = 0.3) + stat_summary(fun = mean, aes(group = genotype), size = 0.7, geom = "line", linetype = "solid")
Apical_lgraph <- Apical_lgraph + stat_compare_means(aes(group = genotype), label = "p.signif", method = "t.test", hide.ns = F, label.y = 5)
Apical_lgraph <- Apical_lgraph + xlab("Day of Treatment") + ylab("Apical Distance (cm)") + rremove("legend")
Apical_lgraph

#Branched distance
Branched_lgraph <- ggplot(data = RSA_comp2, aes(x = Day, y = Branched, group = root_name, color = genotype)) + theme_classic()
Branched_lgraph <- Branched_lgraph + geom_line(alpha = 0.1)
Branched_lgraph <- Branched_lgraph + facet_grid(facet2 ~ treatment)
Branched_lgraph <- Branched_lgraph + stat_summary(fun.data = mean_se, geom = "ribbon", linetype = 0, aes(group = genotype), alpha = 0.3) + stat_summary(fun = mean, aes(group = genotype), size = 0.7, geom = "line", linetype = "solid")
Branched_lgraph <- Branched_lgraph + stat_compare_means(aes(group = genotype), label = "p.signif", method = "t.test", hide.ns = F, label.y = 5)
Branched_lgraph <- Branched_lgraph + xlab("Day of Treatment") + ylab("Branched Distance (cm)") + rremove("legend")
Branched_lgraph

###Growth Rate calculations

Growth_rate <- read.csv("root_names_set_2.csv")
root_name_file <- unique(RSA_MR2$root_name)
length(root_name_file)
## [1] 288
Growth_rate$root_name <- unique(RSA_MR2$root_name)
temporary2 <- subset(RSA_MR2, RSA_MR2$root_name == root_name_file[1])
temporary2
plot(temporary2$MRL ~ temporary2$Day)

models <- lm(temporary2$MRL ~ temporary2$Day)
summary(models)
## 
## Call:
## lm(formula = temporary2$MRL ~ temporary2$Day)
## 
## Residuals:
##        1        2        3        4 
## -0.07333 -0.07598  0.26195 -0.11264 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)   
## (Intercept)     1.01536    0.16655   6.097  0.02586 * 
## temporary2$Day  0.46983    0.03634  12.928  0.00593 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.215 on 2 degrees of freedom
## Multiple R-squared:  0.9882, Adjusted R-squared:  0.9823 
## F-statistic: 167.1 on 1 and 2 DF,  p-value: 0.00593
summary(models)$coefficients[2]
## [1] 0.4698285

##Main Root Growth Rate

Growth_rate$MR_GrowthRate <- 0
Growth_rate$MR_GrowthRate[1] <- summary(models)$coefficients[2] 
Growth_rate
for (i in 1:nrow(Growth_rate)){
  temporary2 <- subset(RSA_MR2, RSA_MR2$root_name == root_name_file[i])
  models <- lm(temporary2$MRL ~ temporary2$Day)
  Growth_rate$MR_GrowthRate[i] <- summary(models)$coefficients[2] 
}
Growth_rate
dim(Growth_rate)
## [1] 288   2

Looks like the 5 rows with NaN for MR_Growthrate are mostly on same plate. 4 are on Pl8, 125 mM; one is pl8_p.1_C125_GC

plate12 <- subset(RSA_MR2, RSA_MR2$plate == 8)
plate12 <- subset(plate12, plate12$treatment == "125")
plate12
plot(plate12$MRL ~ plate12$Day)

# 284 is Pl8_p.1_C125_G7
temporary2 <- subset(RSA_MR2, RSA_MR2$root_name == " Pl8_P.1_C125_G7")
temporary2
models <- lm(temporary2$MRL ~ temporary2$Day)
summary(models)
## 
## Call:
## lm(formula = temporary2$MRL ~ temporary2$Day)
## 
## Residuals:
##        1        2        3 
##  0.03673 -0.05509  0.01836 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)  
## (Intercept)     1.01403    0.08415   12.05   0.0527 .
## temporary2$Day  0.29451    0.01590   18.52   0.0343 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.06871 on 1 degrees of freedom
## Multiple R-squared:  0.9971, Adjusted R-squared:  0.9942 
## F-statistic:   343 on 1 and 1 DF,  p-value: 0.03434
Growth_rate$MR_GrowthRate[284] <- summary(models)$coefficients[2] 

# 283 is Pl8_p.2_C125_G7
temporary2 <- subset(RSA_MR2, RSA_MR2$root_name == " Pl8_P.2_C125_G7")
temporary2
models <- lm(temporary2$MRL ~ temporary2$Day)
summary(models)
## 
## Call:
## lm(formula = temporary2$MRL ~ temporary2$Day)
## 
## Residuals:
##        1        2        3 
## -0.00704  0.01056 -0.00352 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)   
## (Intercept)    1.428661   0.016131   88.57  0.00719 **
## temporary2$Day 0.064315   0.003048   21.10  0.03015 * 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.01317 on 1 degrees of freedom
## Multiple R-squared:  0.9978, Adjusted R-squared:  0.9955 
## F-statistic: 445.1 on 1 and 1 DF,  p-value: 0.03015
Growth_rate$MR_GrowthRate[283] <- summary(models)$coefficients[2] 

# 282 is Pl8_p.3_C125_G7
temporary2 <- subset(RSA_MR2, RSA_MR2$root_name == " Pl8_P.3_C125_GC")
temporary2
models <- lm(temporary2$MRL ~ temporary2$Day)
summary(models)
## 
## Call:
## lm(formula = temporary2$MRL ~ temporary2$Day)
## 
## Residuals:
##        1        2        3 
## -0.05281  0.07921 -0.02640 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)  
## (Intercept)     1.10878    0.12100   9.164   0.0692 .
## temporary2$Day  0.06216    0.02287   2.718   0.2244  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.09879 on 1 degrees of freedom
## Multiple R-squared:  0.8808, Adjusted R-squared:  0.7616 
## F-statistic: 7.388 on 1 and 1 DF,  p-value: 0.2244
Growth_rate$MR_GrowthRate[282] <- summary(models)$coefficients[2] 

# 281 is Pl8_p.4_C125_G7
temporary2 <- subset(RSA_MR2, RSA_MR2$root_name == " Pl8_P.4_C125_GC")
temporary2
models <- lm(temporary2$MRL ~ temporary2$Day)
summary(models)
## 
## Call:
## lm(formula = temporary2$MRL ~ temporary2$Day)
## 
## Residuals:
##        1        2        3 
## -0.02432  0.03647 -0.01216 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)  
## (Intercept)     0.93381    0.05572   16.76   0.0379 *
## temporary2$Day  0.28071    0.01053   26.66   0.0239 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.04549 on 1 degrees of freedom
## Multiple R-squared:  0.9986, Adjusted R-squared:  0.9972 
## F-statistic: 710.7 on 1 and 1 DF,  p-value: 0.02387
Growth_rate$MR_GrowthRate[281] <- summary(models)$coefficients[2] 
Growth_rate

##Lateral root number and average length growth rate

We need to select for plants that eventually produce at least one LR.

To generate list of Root Names - we will look at last day - and subset for LRno>0

#unique(RSA_MR2$Day)
#unique(RSA_MR2$treatment)
#head(RSA_MR2)
ld_tr0 <- subset(RSA_MR2, RSA_MR2$treatment == 0)
ld_tr0 <- subset(ld_tr0, ld_tr0$Day == 4)
ld_tr0 <- subset(ld_tr0, ld_tr0$LRno > 0)
root_names_tr0 <- unique(ld_tr0$root_name)
root_names_tr0
##  [1] " Pl11_p.4_C0_G3" " Pl11_p.3_C0_G3" " Pl11_p.2_C0_G2" " Pl11_p.1_C0_G2"
##  [5] " Pl6_p.3_C0_G6"  " Pl16_p.3_C0_GC" " Pl16_p.2_C0_G7" " Pl16_p.1_C0_G7"
##  [9] " Pl5_p.2_C0_G4"  " Pl5_p.1_C0_G4"  " Pl14_p.4_C0_G6" " Pl14_p.2_C0_G5"
## [13] " Pl14_p.1_C0_G5" " Pl24_p.3_C0_GC" " Pl10_p.3_C0_G2" " Pl2_p.3_C0_G2" 
## [17] " Pl2_p.1_C0_G1"  " Pl3_p.2_C0_G2"  " Pl1_p.3_C0_G1"  " Pl1_p.2_C0_GC" 
## [21] " Pl1_p.1_C0_GC"  " Pl17_p.3_C0_G1" " Pl17_p.2_C0_GC" " Pl17_p.1_C0_GC"
## [25] " Pl18_p.4_C0_G2" " Pl18_p.3_C0_G2" " Pl20_p.4_C0_G4" " Pl20_p.3_C0_G4"
## [29] " Pl20_p.2_C0_G3" " Pl20_p.1_C0_G3" " Pl22_p.4_C0_G6" " Pl22_p.3_C0_G6"
## [33] " Pl22_p.2_C0_G5" " Pl22_p.1_C0_G5" " Pl23_p.4_C0_G7" " Pl23_p.3_C0_G7"
## [37] " Pl23_p.2_C0_G6" " Pl4_p.4_C0_G4"  " Pl7_p.3_C0_G7"  " Pl7_p.2_C0_G6" 
## [41] " Pl13_p.3_C0_G5" " Pl13_p.2_C0_G4" " Pl19_p.4_C0_G3" " Pl19_p.1_C0_G2"
## [45] " Pl12_p.4_C0_G4" " Pl12_p.3_C0_G4" " Pl12_p.2_C0_G3" " Pl12_p.1_C0_G3"
ld_tr75 <- subset(RSA_MR2, RSA_MR2$treatment == 75)
ld_tr75 <- subset(ld_tr75, ld_tr75$Day == 8)
ld_tr75 <- subset(ld_tr75, ld_tr75$LRno > 0)
root_names_tr75 <- unique(ld_tr75$root_name)
root_names_tr75
##  [1] " Pl8_p.4_C75_GC"  " Pl8_p.3_C75_GC"  " Pl8_p.2_C75_G7"  " Pl8_p.1_C75_G7" 
##  [5] " Pl7_p.4_C75_G7"  " Pl7_p.3_C75_G7"  " Pl7_p.1_C75_G6"  " Pl3_p.4_C75_G3" 
##  [9] " Pl3_p.3_C75_G3"  " Pl3_p.2_C75_G2"  " Pl22_p.3_C75_G6" " Pl22_p.2_C75_G5"
## [13] " Pl16_p.3_C75_GC" " Pl16_p.1_C75_G7" " Pl4_p.4_C75_G4"  " Pl4_p.3_C75_G4" 
## [17] " Pl4_p.2_C75_G3"  " Pl18_p.4_C75_G2" " Pl18_p.3_C75_G2" " Pl18_p.1_C75_G1"
## [21] " Pl15_p.3_C75_G7" " Pl15_p.4_C75_G7" " Pl15_p.2_C75_G6" " Pl15_p.1_C75_G6"
## [25] " Pl23_p.3_C75_G7" " Pl23_p.2_C75_G6" " Pl23_p.1_C75_G6" " Pl24_p.3_C75_GC"
## [29] " Pl24_p.2_C75_G7" " Pl6_p.4_C75_G6"  " Pl6_p.3_C75_G6"  " Pl6_p.2_C75_G5" 
## [33] " Pl10_p.4_C75_G2" " Pl10_p.1_C75_G1" " Pl21_p.3_C75_G5" " Pl13_p.4_C75_G5"
## [37] " Pl13_p.3_C75_G5" " Pl14_p.4_C75_G6" " Pl14_p.3_C75_G6" " Pl17_p.3_C75_G1"
## [41] " Pl17_p.1_C75_GC" " Pl2_p.4_C75_G2"  " Pl2_p.3_C75_G2"  " Pl2_p.2_C75_G1" 
## [45] " Pl2_p.1_C75_G1"  " Pl9_p.4_C75_G1"  " Pl9_p.3_C75_G1"  " Pl9_p.2_C75_GC" 
## [49] " Pl9_p.1_C75_GC"  " Pl11_p.4_C75_G3" " Pl11_p.3_C75_G3" " Pl11_p.1_C75_G2"
## [53] " Pl1_p.4_C75_G1"  " Pl1_p.3_C75_G1"  " Pl1_p.1_C75_GC"  " Pl5_p.4_C75_G5" 
## [57] " Pl5_p.3_C75_G5"  " Pl5_p.2_C75_G4"  " Pl5_p.1_C75_G4"  " Pl12_p.4_C75_G4"
## [61] " Pl12_p.2_C75_G3" " Pl12_p.1_C75_G3"
ld_tr125 <- subset(RSA_MR2, RSA_MR2$treatment == 125)
ld_tr125 <- subset(ld_tr125, ld_tr125$Day == 8)
ld_tr125 <- subset(ld_tr125, ld_tr125$LRno > 0)
root_names_tr125 <- unique(ld_tr125$root_name)
root_names_tr125
##  [1] " Pl8_P.4_C125_GC"  " Pl18_p.4_C125_G2" " Pl18_p.3_C125_G2"
##  [4] " Pl22_p.4_C125_G6" " Pl12_p.1_C125_G3" " Pl3_p.4_C125_G3" 
##  [7] " Pl3_p.2_C125_G2"  " Pl3_p.1_C125_G2"  " Pl5_p.4_C125_G5" 
## [10] " Pl5_p.3_C125_G5"  " Pl15_p.4_C125_G7" " Pl19_p.4_C125_G3"
## [13] " Pl19_p.3_C125_G3" " Pl19_p.2_C125_G2" " Pl19_p.1_C125_G2"
## [16] " Pl13_p.4_C125_G5" " Pl13_p.2_C125_G4" " Pl17_p.4_C125_G1"
## [19] " Pl2_p.3_C125_G2"  " Pl16_p.4_C125_GC" " Pl16_p.3_C125_GC"
## [22] " Pl16_p.1_C125_G7" " Pl11_p.3_C125_G3" " Pl11_p.2_C125_G2"
## [25] " Pl4_p.3_C125_G4"  " Pl4_p.1_C125_G3"  " Pl1_p.3_C125_G1" 
## [28] " Pl1_p.2_C125_GC"  " Pl10_p.4_C125_G2" " Pl10_p.3_C125_G2"
## [31] " Pl24_p.2_C125_G7" " Pl24_p.1_C125_G7" " Pl21_p.3_C125_G5"
## [34] " Pl9_p.4_C125_G1"  " Pl9_p.2_C125_GC"
roots_with_LR <- c(root_names_tr0, root_names_tr75, root_names_tr125)
roots_with_LR
##   [1] " Pl11_p.4_C0_G3"   " Pl11_p.3_C0_G3"   " Pl11_p.2_C0_G2"  
##   [4] " Pl11_p.1_C0_G2"   " Pl6_p.3_C0_G6"    " Pl16_p.3_C0_GC"  
##   [7] " Pl16_p.2_C0_G7"   " Pl16_p.1_C0_G7"   " Pl5_p.2_C0_G4"   
##  [10] " Pl5_p.1_C0_G4"    " Pl14_p.4_C0_G6"   " Pl14_p.2_C0_G5"  
##  [13] " Pl14_p.1_C0_G5"   " Pl24_p.3_C0_GC"   " Pl10_p.3_C0_G2"  
##  [16] " Pl2_p.3_C0_G2"    " Pl2_p.1_C0_G1"    " Pl3_p.2_C0_G2"   
##  [19] " Pl1_p.3_C0_G1"    " Pl1_p.2_C0_GC"    " Pl1_p.1_C0_GC"   
##  [22] " Pl17_p.3_C0_G1"   " Pl17_p.2_C0_GC"   " Pl17_p.1_C0_GC"  
##  [25] " Pl18_p.4_C0_G2"   " Pl18_p.3_C0_G2"   " Pl20_p.4_C0_G4"  
##  [28] " Pl20_p.3_C0_G4"   " Pl20_p.2_C0_G3"   " Pl20_p.1_C0_G3"  
##  [31] " Pl22_p.4_C0_G6"   " Pl22_p.3_C0_G6"   " Pl22_p.2_C0_G5"  
##  [34] " Pl22_p.1_C0_G5"   " Pl23_p.4_C0_G7"   " Pl23_p.3_C0_G7"  
##  [37] " Pl23_p.2_C0_G6"   " Pl4_p.4_C0_G4"    " Pl7_p.3_C0_G7"   
##  [40] " Pl7_p.2_C0_G6"    " Pl13_p.3_C0_G5"   " Pl13_p.2_C0_G4"  
##  [43] " Pl19_p.4_C0_G3"   " Pl19_p.1_C0_G2"   " Pl12_p.4_C0_G4"  
##  [46] " Pl12_p.3_C0_G4"   " Pl12_p.2_C0_G3"   " Pl12_p.1_C0_G3"  
##  [49] " Pl8_p.4_C75_GC"   " Pl8_p.3_C75_GC"   " Pl8_p.2_C75_G7"  
##  [52] " Pl8_p.1_C75_G7"   " Pl7_p.4_C75_G7"   " Pl7_p.3_C75_G7"  
##  [55] " Pl7_p.1_C75_G6"   " Pl3_p.4_C75_G3"   " Pl3_p.3_C75_G3"  
##  [58] " Pl3_p.2_C75_G2"   " Pl22_p.3_C75_G6"  " Pl22_p.2_C75_G5" 
##  [61] " Pl16_p.3_C75_GC"  " Pl16_p.1_C75_G7"  " Pl4_p.4_C75_G4"  
##  [64] " Pl4_p.3_C75_G4"   " Pl4_p.2_C75_G3"   " Pl18_p.4_C75_G2" 
##  [67] " Pl18_p.3_C75_G2"  " Pl18_p.1_C75_G1"  " Pl15_p.3_C75_G7" 
##  [70] " Pl15_p.4_C75_G7"  " Pl15_p.2_C75_G6"  " Pl15_p.1_C75_G6" 
##  [73] " Pl23_p.3_C75_G7"  " Pl23_p.2_C75_G6"  " Pl23_p.1_C75_G6" 
##  [76] " Pl24_p.3_C75_GC"  " Pl24_p.2_C75_G7"  " Pl6_p.4_C75_G6"  
##  [79] " Pl6_p.3_C75_G6"   " Pl6_p.2_C75_G5"   " Pl10_p.4_C75_G2" 
##  [82] " Pl10_p.1_C75_G1"  " Pl21_p.3_C75_G5"  " Pl13_p.4_C75_G5" 
##  [85] " Pl13_p.3_C75_G5"  " Pl14_p.4_C75_G6"  " Pl14_p.3_C75_G6" 
##  [88] " Pl17_p.3_C75_G1"  " Pl17_p.1_C75_GC"  " Pl2_p.4_C75_G2"  
##  [91] " Pl2_p.3_C75_G2"   " Pl2_p.2_C75_G1"   " Pl2_p.1_C75_G1"  
##  [94] " Pl9_p.4_C75_G1"   " Pl9_p.3_C75_G1"   " Pl9_p.2_C75_GC"  
##  [97] " Pl9_p.1_C75_GC"   " Pl11_p.4_C75_G3"  " Pl11_p.3_C75_G3" 
## [100] " Pl11_p.1_C75_G2"  " Pl1_p.4_C75_G1"   " Pl1_p.3_C75_G1"  
## [103] " Pl1_p.1_C75_GC"   " Pl5_p.4_C75_G5"   " Pl5_p.3_C75_G5"  
## [106] " Pl5_p.2_C75_G4"   " Pl5_p.1_C75_G4"   " Pl12_p.4_C75_G4" 
## [109] " Pl12_p.2_C75_G3"  " Pl12_p.1_C75_G3"  " Pl8_P.4_C125_GC" 
## [112] " Pl18_p.4_C125_G2" " Pl18_p.3_C125_G2" " Pl22_p.4_C125_G6"
## [115] " Pl12_p.1_C125_G3" " Pl3_p.4_C125_G3"  " Pl3_p.2_C125_G2" 
## [118] " Pl3_p.1_C125_G2"  " Pl5_p.4_C125_G5"  " Pl5_p.3_C125_G5" 
## [121] " Pl15_p.4_C125_G7" " Pl19_p.4_C125_G3" " Pl19_p.3_C125_G3"
## [124] " Pl19_p.2_C125_G2" " Pl19_p.1_C125_G2" " Pl13_p.4_C125_G5"
## [127] " Pl13_p.2_C125_G4" " Pl17_p.4_C125_G1" " Pl2_p.3_C125_G2" 
## [130] " Pl16_p.4_C125_GC" " Pl16_p.3_C125_GC" " Pl16_p.1_C125_G7"
## [133] " Pl11_p.3_C125_G3" " Pl11_p.2_C125_G2" " Pl4_p.3_C125_G4" 
## [136] " Pl4_p.1_C125_G3"  " Pl1_p.3_C125_G1"  " Pl1_p.2_C125_GC" 
## [139] " Pl10_p.4_C125_G2" " Pl10_p.3_C125_G2" " Pl24_p.2_C125_G7"
## [142] " Pl24_p.1_C125_G7" " Pl21_p.3_C125_G5" " Pl9_p.4_C125_G1" 
## [145] " Pl9_p.2_C125_GC"
LR_only <- subset(RSA_MR2, RSA_MR2$root_name %in% roots_with_LR)
LR_only
temporary3 <- subset(LR_only, LR_only$root_name == root_name_file[1])
temporary3
plot(temporary3$LRno ~ temporary3$Day)

models2 <- lm(temporary3$LRno ~ temporary3$Day)
summary(models2)
## 
## Call:
## lm(formula = temporary3$LRno ~ temporary3$Day)
## 
## Residuals:
##          1          2          3          4 
## -5.714e-01  2.220e-16  8.571e-01 -2.857e-01 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)
## (Intercept)    -2.220e-16  5.855e-01   0.000    1.000
## temporary3$Day  2.857e-01  1.278e-01   2.236    0.155
## 
## Residual standard error: 0.7559 on 2 degrees of freedom
## Multiple R-squared:  0.7143, Adjusted R-squared:  0.5714 
## F-statistic:     5 on 1 and 2 DF,  p-value: 0.1548
summary(models2)$coefficients[2]
## [1] 0.2857143
Growth_rate$LRno_GrowthRate <- 0
Growth_rate$LRno_GrowthRate[1] <- summary(models2)$coefficients[2] 
Growth_rate
for (i in 2:nrow(Growth_rate)){
  temporary3 <- subset(LR_only, LR_only$root_name == root_name_file[i])
  if(dim(temporary3)[1] < 1){
    Growth_rate$LRno_GrowthRate[i] <- 0
  } else {
    models2 <- lm(temporary3$LRno ~ temporary3$Day)
    Growth_rate$LRno_GrowthRate[i] <- summary(models2)$coefficients[2] 
  }
}
Growth_rate
LR_only$LRL_avg <- 0

for (i in 1:nrow(LR_only)){
  if(LR_only$LRL[i] > 0){
    LR_only$LRL_avg[i] <- LR_only$LRL[i] / LR_only$LRno[i] 
  }
  else{
    LR_only$LRL_avg[i] <- 0
  }
}
LR_only

LRL_avg growth rate

Growth_rate$LRLavg_GrowthRate <- 0
temporary4 <- subset(LR_only, LR_only$root_name == root_name_file[1])
temporary4
plot(temporary4$LRL_avg ~ temporary4$Day)

models3 <- lm(temporary4$LRL_avg ~ temporary4$Day)
summary(models3)$coefficients[2]
## [1] 0.03472133
Growth_rate$LRLavg_GrowthRate[1] <- summary(models3)$coefficients[2]
Growth_rate
for (i in 1:nrow(Growth_rate)){
  temporary4 <- subset(LR_only, LR_only$root_name == root_name_file[i])
  temporary4
  if(dim(temporary4)[1] > 0){
    models3 <- lm(temporary4$LRL_avg ~ temporary4$Day)
    Growth_rate$LRLavg_GrowthRate[i] <- summary(models3)$coefficients[2]  
  } else{
    Growth_rate$LRLavg_GrowthRate[i] <- 0
  }
  
}
Growth_rate
RSA_MR2

###Growth Rate plots Adding root_name info

Growth_rate$info <- strsplit(Growth_rate$root_name, "_")
Growth_rate$info[1]
## [[1]]
## [1] " Pl8" "p.4"  "C75"  "GC"
Growth_rate$plate <- "NA"
Growth_rate$plant <- "NA"
Growth_rate$treatment <- "NA"
Growth_rate$genotype <- "NA"


for(i in 1:nrow(Growth_rate)){
   Growth_rate$plate[i] <- Growth_rate$info[[i]][1]
   Growth_rate$plant[i] <- Growth_rate$info[[i]][2]
   Growth_rate$treatment[i] <- Growth_rate$info[[i]][3]
   Growth_rate$genotype[i] <- Growth_rate$info[[i]][4]
}
Growth_rate
Growth_rate$plate <- gsub("Pl", "", Growth_rate$plate)
Growth_rate$plate <- as.numeric(as.character(Growth_rate$plate))

# same for genotype
Growth_rate$genotype <- gsub("GC", "Col-0", Growth_rate$genotype)
Growth_rate$genotype <- gsub("G1", "170-3F", Growth_rate$genotype)
Growth_rate$genotype <- gsub("G2", "170-4F", Growth_rate$genotype)
Growth_rate$genotype <- gsub("G3", "170-5A", Growth_rate$genotype)
Growth_rate$genotype <- gsub("G4", "190-2B", Growth_rate$genotype)
Growth_rate$genotype <- gsub("G5", "200-1A", Growth_rate$genotype)
Growth_rate$genotype <- gsub("G6", "200-2B", Growth_rate$genotype)
Growth_rate$genotype <- gsub("G7", "200-3B", Growth_rate$genotype)
# same for treatment
Growth_rate$treatment <- gsub("C", "", Growth_rate$treatment)
Growth_rate$treatment <- as.factor(as.character(Growth_rate$treatment))
Growth_rate$treatment <- factor(Growth_rate$treatment, level = c(0, 75, 125))
#same for plant
Growth_rate$plant <- gsub("p.", "P.", Growth_rate$plant)
Growth_rate$plant <- gsub("P.", "", Growth_rate$plant)
#check
unique(Growth_rate$genotype)
## [1] "Col-0"  "200-3B" "200-2B" "200-1A" "170-4F" "170-3F" "190-2B" "170-5A"
unique(Growth_rate$plate)
##  [1]  8  7 22 18 15 12 20 21  3 11  5  6 19 13 16 23  4 17 14  2 24 10  1  9
unique(Growth_rate$plant)
## [1] "4" "1" "3" "2"
unique(Growth_rate$treatment)
## [1] 75  125 0  
## Levels: 0 75 125
#re-orderselect columns
Growth_rate$genotype <- factor(Growth_rate$genotype, level = c("Col-0", "170-3F", "170-4F", "170-5A", "190-2B", "200-1A", "200-2B", "200-3B"))
" Pl12_p.4_C75_G4" 
## [1] " Pl12_p.4_C75_G4"
temp_super <- subset(RSA_MR2, RSA_MR2$plate == 12)
temp_super <- subset(temp_super, temp_super$treatment == 75)
temp_super
plot(temp_super$MRL ~ temp_super$Day)

unique(temp_super$root_name)
## [1] " Pl12_p.4_C75_G4" " Pl12_p.3_C75_G4" " Pl12_p.2_C75_G3" " Pl12_p.1_C75_G3"
MR_GR_scatter <- ggerrorplot(Growth_rate, y = "MR_GrowthRate", x = "genotype", na.rm = TRUE, fill = "genotype", color = "genotype", facet.by = c("treatment"), ncol = 4, desc_stat = "mean_sd", add = "jitter", add.params = list(color = "darkgray"), xlab = "Mutant Line", ylab = "MR Growth Rate")
MR_GR_scatter <- MR_GR_scatter + rremove("legend") + stat_compare_means(method = "t.test", ref.group = "Col-0", label = "p.signif", hide.ns = FALSE)
MR_GR_scatter <- MR_GR_scatter + theme(axis.text.x = element_text(angle = 90))
MR_GR_scatter <- MR_GR_scatter + scale_colour_manual(values = c("midnightblue", "orange", "orange", "orange", "darkgreen", "firebrick", "firebrick", "firebrick"))
MR_GR_scatter
## Warning: Removed 1 rows containing non-finite values (stat_summary).
## Warning: Removed 1 rows containing non-finite values (stat_compare_means).
## Warning: Removed 1 rows containing missing values (geom_point).

jpeg("MR_GR_scatter.jpg")
plot(MR_GR_scatter)
## Warning: Removed 1 rows containing non-finite values (stat_summary).
## Warning: Removed 1 rows containing non-finite values (stat_compare_means).
## Warning: Removed 1 rows containing missing values (geom_point).
dev.off()
## png 
##   2
LRno_GR_scatter <- ggerrorplot(Growth_rate, y = "LRno_GrowthRate", x = "genotype", na.rm = TRUE, fill = "genotype", color = "genotype", facet.by = c("treatment"), ncol = 4, desc_stat = "mean_sd", add = "jitter", add.params = list(color = "darkgray"), xlab = "Mutant Line", ylab = "LR number Growth Rate")
LRno_GR_scatter <- LRno_GR_scatter + rremove("legend") + stat_compare_means(method = "t.test", ref.group = "Col-0", label = "p.signif", hide.ns = FALSE)
LRno_GR_scatter <- LRno_GR_scatter + theme(axis.text.x = element_text(angle = 90))
LRno_GR_scatter <- LRno_GR_scatter + scale_colour_manual(values = c("midnightblue", "orange", "orange", "orange", "darkgreen", "firebrick", "firebrick", "firebrick"))
LRno_GR_scatter

LRLavg_GR_scatter <- ggerrorplot(Growth_rate, y = "LRLavg_GrowthRate", x = "genotype", na.rm = TRUE, fill = "genotype", color = "genotype", facet.by = c("treatment"), ncol = 4, desc_stat = "mean_sd", add = "jitter", add.params = list(color = "darkgray"), xlab = "Mutant Line", ylab = "LRL average Growth Rate")
LRLavg_GR_scatter <- LRLavg_GR_scatter + rremove("legend") + stat_compare_means(method = "t.test", ref.group = "Col-0", label = "p.signif", hide.ns = FALSE)
LRLavg_GR_scatter <- LRLavg_GR_scatter + theme(axis.text.x = element_text(angle = 90))
LRLavg_GR_scatter <- LRLavg_GR_scatter + scale_colour_manual(values = c("midnightblue", "orange", "orange", "orange", "darkgreen", "firebrick", "firebrick", "firebrick"))
LRLavg_GR_scatter

##Relative Growth Rate steps: find average GR of each genotype under control.

#install.packages("doBy")
library(doBy)
## Warning: package 'doBy' was built under R version 4.1.2
sum_GrowthRate <- summaryBy(MR_GrowthRate + LRno_GrowthRate + LRLavg_GrowthRate ~ genotype + treatment, data = Growth_rate)
sum_GrowthRate
sum_GrowthRateC <- subset(sum_GrowthRate, sum_GrowthRate$treatment == "0")
sum_GrowthRateC
#remove treatment column and rename all other columns as "Control.avg":

sum_GrowthRateC <- sum_GrowthRateC[,c(1,3:5)]
colnames(sum_GrowthRateC) <- gsub(".mean", ".C.avg", colnames(sum_GrowthRateC))
sum_GrowthRateC

merge this with the original GR file:

GrowthRate_STI <- merge(Growth_rate,  sum_GrowthRateC, by = "genotype", all = TRUE)
dim(Growth_rate)
## [1] 288   9
dim(GrowthRate_STI)
## [1] 288  12
GrowthRate_STI

Calculate RELATIVE GRs per each genotype

GrowthRate_STI$MR.STI <- GrowthRate_STI$MR_GrowthRate / GrowthRate_STI$MR_GrowthRate.C.avg
GrowthRate_STI$LRno.STI <- GrowthRate_STI$LRno_GrowthRate / GrowthRate_STI$LRno_GrowthRate.C.avg
GrowthRate_STI$aLRL.STI <- GrowthRate_STI$LRLavg_GrowthRate / GrowthRate_STI$LRLavg_GrowthRate.C.avg
GrowthRate_STI
MR_STIset2_errorplot <- ggerrorplot(GrowthRate_STI, y = "MR.STI", x = "genotype", na.rm = TRUE, fill = "genotype", color = "genotype",
                                   facet.by = c("treatment"), ncol = 4, 
                                   desc_stat = "mean_sd", add = "jitter",
                                   add.params = list(color = "darkgray"),
                                   xlab = "DUF Mutant Line", ylab = "Main Root Salt Tolerance Index")
MR_STIset2_errorplot <- MR_STIset2_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref.group = "Col-0", label = "p.signif", hide.ns = TRUE)
MR_STIset2_errorplot <- MR_STIset2_errorplot + theme(axis.text.x = element_text(angle = 90))
MR_STIset2_errorplot <- MR_STIset2_errorplot + scale_colour_manual(values = c("midnightblue", "orange", "orange", "orange", "darkgreen", "firebrick", "firebrick", "firebrick"))
MR_STIset2_errorplot
## Warning: Removed 1 rows containing non-finite values (stat_summary).
## Warning: Removed 1 rows containing non-finite values (stat_compare_means).
## Warning: Removed 1 rows containing missing values (geom_point).

jpeg("MR_STIset2_errorplot.jpg")
plot(MR_STIset2_errorplot)
## Warning: Removed 1 rows containing non-finite values (stat_summary).
## Warning: Removed 1 rows containing non-finite values (stat_compare_means).
## Warning: Removed 1 rows containing missing values (geom_point).
dev.off()
## png 
##   2
LRno_STIset2_errorplot <- ggerrorplot(GrowthRate_STI, y = "LRno.STI", x = "genotype", na.rm = TRUE, fill = "genotype", color = "genotype",
                                   facet.by = c("treatment"), ncol = 4, 
                                   desc_stat = "mean_sd", add = "jitter",
                                   add.params = list(color = "darkgray"),
                                   xlab = "DUF Mutant Line", ylab = "Lateral Root Number Salt Tolerance Index")
LRno_STIset2_errorplot <- LRno_STIset2_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref.group = "Col-0", label = "p.signif", hide.ns = TRUE)
LRno_STIset2_errorplot <- LRno_STIset2_errorplot + theme(axis.text.x = element_text(angle = 90))
LRno_STIset2_errorplot <- LRno_STIset2_errorplot + scale_colour_manual(values = c("midnightblue", "orange", "orange", "orange", "darkgreen", "firebrick", "firebrick", "firebrick"))
LRno_STIset2_errorplot

aLRL_STIset2_errorplot <- ggerrorplot(GrowthRate_STI, y = "aLRL.STI", x = "genotype", na.rm = TRUE, fill = "genotype", color = "genotype",
                                   facet.by = c("treatment"), ncol = 4, 
                                   desc_stat = "mean_sd", add = "jitter",
                                   add.params = list(color = "darkgray"),
                                   xlab = "DUF Mutant Line", ylab = "Average Lateral Root Salt Tolerance Index")
aLRL_STIset2_errorplot <- aLRL_STIset2_errorplot + rremove("legend") + stat_compare_means(method = "t.test", ref.group = "Col-0", label = "p.signif", hide.ns = TRUE)
aLRL_STIset2_errorplot <- aLRL_STIset2_errorplot + theme(axis.text.x = element_text(angle = 90))
aLRL_STIset2_errorplot <- aLRL_STIset2_errorplot + scale_colour_manual(values = c("midnightblue", "orange", "orange", "orange", "darkgreen", "firebrick", "firebrick", "firebrick"))
aLRL_STIset2_errorplot