Checking if the BackTracer will work for the SPIRO collected images (Col-0 and C24 ransferred to 0, 125 mM NaCl or SPRAYED with 0 or 125 mM NaCl) - img every 20 minutes). The seedlings were transferred when they were 7 days old. Germinated on 1/2 MS medium, 10% Dashin Agar, 0.5% sucrose, 0.1% MES buffer (pH 5.8 KOH). The images were acquired using SPIRO and processed with SmartRoot and BackTracker as described in the protocol here.

pre-processing the data:

list.files(pattern=".csv")
## [1] "20220131_Plate01.csv" "20220131_Plate02.csv" "20220131_Plate03.csv"
## [4] "20220131_Plate04.csv" "decoding_roots.csv"
pl1 <- read.csv("20220131_Plate01.csv")
pl2 <- read.csv("20220131_Plate02.csv")
pl3 <- read.csv("20220131_Plate03.csv")
pl4 <- read.csv("20220131_Plate04.csv")
pl1
pl2
pl3
pl4

Let’s fuse all the plates:

pl_all <- rbind(pl1, pl2)
pl_all <- rbind(pl_all, pl3)
pl_all <- rbind(pl_all, pl4)
pl_all
unique(pl_all$root_name)
##  [1] " root_0"  " root_1"  " root_2"  " root_3"  " root_4"  " root_5" 
##  [7] " root_6"  " root_7"  " root_8"  " root_9"  " root_10" " root_11"
## [13] " root_12" " root_13" " root_14" " root_15" " root_16" " root_17"
## [19] " root_18" " root_19" " root_20" " root_21" " root_22" " root_23"
## [25] " root_24" " root_25" " root_26"
length(unique(pl_all$root))
## [1] 13200

OK - let’s see if we can see a pattern if we plot the data over time while grouping per “root_name”.

Let’s extract time:

pl_all$info <- strsplit(pl_all$image, "-")
pl_all$info[1]
## [[1]]
## [1] "plate1"   "20220201" "203543"   "da.rsml"
for(i in 1:nrow(pl_all)){
  pl_all$plate[i] <- pl_all$info[i][[1]][1]
  pl_all$date[i] <- pl_all$info[i][[1]][2]
  pl_all$time[i] <- pl_all$info[i][[1]][3]
}

pl_all

We now need to extract time - as in date from the everything - and see what is the first timepoint on the 31st of January - from which we will calculate all other timepoints

pl_all$month <- substr(pl_all$date, 5, 6)
pl_all$day <- substr(pl_all$date, 7, 8)
pl_all$hour <- substr(pl_all$time, 1, 2)
pl_all$min <- substr(pl_all$time, 3, 4)
pl_all
unique(pl_all$date)
## [1] "20220201" "20220131" "20220202"
temp <- subset(pl_all, pl_all$date == "20220131")
unique(temp$time)
##   [1] "191455" "193508" "115454" "145455" "101445" "151454" "225509" "185455"
##   [9] "155452" "105443" "203504" "111442" "211501" "213500" "141458" "173459"
##  [17] "233506" "121452" "201505" "221512" "195506" "123451" "093445" "223511"
##  [25] "103444" "133446" "205503" "231508" "143456" "171500" "215500" "235505"
##  [33] "161450" "183456" "175458" "131448" "125450" "165502" "153453" "095447"
##  [41] "181457" "113455" "135445" "163449" "181516" "183515" "135505" "223527"
##  [49] "103502" "213519" "201523" "173517" "141516" "143515" "153511" "115512"
##  [57] "193526" "191513" "233523" "095505" "161508" "221528" "165520" "151513"
##  [65] "203523" "225526" "125508" "111501" "195526" "163507" "123509" "231525"
##  [73] "113513" "155510" "105501" "133505" "175516" "101504" "211520" "215518"
##  [81] "093506" "205521" "145514" "171519" "131507" "235521" "121511" "185514"
##  [89] "173536" "111519" "191531" "115530" "195544" "205540" "215536" "221545"
##  [97] "211538" "181534" "101522" "185533" "171537" "141535" "103521" "145532"
## [105] "153530" "235537" "131525" "143533" "105520" "113532" "213537" "123528"
## [113] "163526" "155529" "223545" "183533" "135523" "193545" "201542" "151535"
## [121] "175536" "165539" "133525" "121529" "231542" "203541" "161526" "093527"
## [129] "225542" "233541" "125526" "095523" "155547" "103539" "101541" "131543"
## [137] "225558" "123546" "221601" "145550" "215555" "193603" "191550" "171555"
## [145] "185551" "115548" "143554" "231558" "205558" "233557" "173554" "133543"
## [153] "181554" "153548" "121547" "111537" "165557" "161545" "175554" "125545"
## [161] "203559" "213556" "235554" "093545" "183552" "223601" "151554" "113550"
## [169] "211556" "141553" "135541" "201600" "105538" "163544" "195603" "095542"

seems like 09:35 is the 1st time point of our experiment:

pl_all$min <- as.numeric(as.character(pl_all$min))
pl_all$hour <- as.numeric(as.character(pl_all$hour))
pl_all$day <- as.numeric(as.character(pl_all$day))
pl_all$month <- as.numeric(as.character(pl_all$month))
pl_all$TOE <- (pl_all$min - 35) + (pl_all$hour - 9)*60 + (pl_all$day - 31)*24*60 + (pl_all$month - 1)*31*24*60
pl_all
library(ggplot2)
pl_all$ID <- paste(pl_all$plate, pl_all$root_name, sep="_")
pl_all$ID <- gsub(" ", "", pl_all$ID)
pl_all$root_name <- gsub(" ", "", pl_all$root_name)
# let's remove last timepoint - since the roots are named differently in the last traced picture
max(pl_all$TOE)
## [1] 3081
pl_all <- subset(pl_all, pl_all$TOE < 3075)


root_lgraph <- ggplot(data=pl_all, aes(x= TOE, y=length, group = ID, color = plate)) 
root_lgraph <- root_lgraph + geom_line(alpha = 0.1) 
root_lgraph <- root_lgraph + stat_summary(fun.data = mean_se, geom="ribbon", linetype=0, aes(group=plate), alpha=0.3) + stat_summary(fun=mean, aes(group= plate),  size=0.7, geom="line", linetype = "dashed")
root_lgraph <- root_lgraph + ylab("Root Length (cm)") + xlab("Minutes After Stress")
root_lgraph

OK - so clearly - there is a LOT of noise in here - let’s assign the individual roots their genotype and treatment and go through the data curation step-by-step:

decode <- read.csv("decoding_roots.csv")
decode$ID <- paste(decode$plate, decode$root_name, sep="_")
decode
unique(pl_all$root_name)
##  [1] "root_0"  "root_1"  "root_2"  "root_3"  "root_4"  "root_5"  "root_6" 
##  [8] "root_7"  "root_8"  "root_9"  "root_10" "root_11" "root_12" "root_13"
## [15] "root_14" "root_15" "root_16" "root_17" "root_18" "root_19" "root_20"
## [22] "root_21" "root_22" "root_23" "root_24" "root_25"

Let’s fuse the roots with their decoding information now:

library(reshape2)
all_deco <- merge(pl_all, decode, by = c("ID", "root_name", "plate"),   all=TRUE)
all_deco
dim(pl_all)
## [1] 13238    29
dim(all_deco)
## [1] 13238    32

data curation

Cool - FIRST let’s remove all of the points that are: 1) more than 0.3 cm larger than the previous datapoint 2) LESS than previous datapoint

For this - we will need to separate each root individually, sort it based on TOE (time of experiment) and calculate difference between individual root lengths:

temp_root <- subset(all_deco, all_deco$ID == unique(all_deco$ID[1]))
temp_root
plot(temp_root$length ~ temp_root$TOE)

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
temp2 <- temp_root %>% arrange(TOE)
temp2$diff <- 0
for(i in 2:nrow(temp2)){
  temp2$diff[i] <- temp2$length[i] - temp2$length[i-1]
}


temp3 <- subset(temp2, temp2$diff < 0.3)
temp4 <- subset(temp2, temp2$diff > 0)
temp4
plot(temp4$length ~ temp4$TOE)

for(i in 2:nrow(temp4)){
  temp4$diff[i] <- temp4$length[i] - temp4$length[i-1]
}
temp5 <- subset(temp4, temp4$diff > 0)
plot(temp5$length ~ temp5$TOE)

for(i in 2:nrow(temp5)){
  temp5$diff[i] <- temp5$length[i] - temp5$length[i-1]
}
temp6 <- subset(temp5, temp5$diff > 0)
plot(temp6$length ~ temp6$TOE)

ok - three rounds of removing the length differences more than 0 seems sufficient for this example. Let’s save it as double_cur data.

double_cur <- temp6
double_cur

Let’s see how it looks like for the ENTIRE population. So first we need to loop the above command:

root_IDs <- unique(all_deco$ID)
length(root_IDs)
## [1] 86
for(i in 2:53){
  temp_root <- subset(all_deco, all_deco$ID == root_IDs[i])
  temp2 <- temp_root %>% arrange(TOE)
  temp2$diff <- 0
  for(m in 2:nrow(temp2)){
  temp2$diff[m] <- temp2$length[m] - temp2$length[m-1]
  }
  temp3 <- subset(temp2, temp2$diff < 0.3)
  temp4 <- subset(temp3, temp3$diff > 0)
  temp4 <- temp4 %>% arrange(TOE)
  for(n in 2:nrow(temp4)){
    temp4$diff[n] <- temp4$length[n] - temp4$length[n-1]
  }
  temp5 <- subset(temp4, temp4$diff > 0)
  temp5 <- temp5 %>% arrange(TOE)
  for(o in 2:nrow(temp5)){
    temp5$diff[o] <- temp5$length[o] - temp5$length[o-1]
  }
  temp6 <- subset(temp5, temp5$diff > 0)
  double_cur <- rbind(double_cur, temp6)
}

for(i in 55:57){
  temp_root <- subset(all_deco, all_deco$ID == root_IDs[i])
  temp2 <- temp_root %>% arrange(TOE)
  temp2$diff <- 0
  for(m in 2:nrow(temp2)){
  temp2$diff[m] <- temp2$length[m] - temp2$length[m-1]
  }
  temp3 <- subset(temp2, temp2$diff < 0.3)
  temp4 <- subset(temp3, temp3$diff > 0)
  temp4 <- temp4 %>% arrange(TOE)
  for(n in 2:nrow(temp4)){
    temp4$diff[n] <- temp4$length[n] - temp4$length[n-1]
  }
  temp5 <- subset(temp4, temp4$diff > 0)
  temp5 <- temp5 %>% arrange(TOE)
  for(o in 2:nrow(temp5)){
    temp5$diff[o] <- temp5$length[o] - temp5$length[o-1]
  }
  temp6 <- subset(temp5, temp5$diff > 0)
  double_cur <- rbind(double_cur, temp6)
}

for(i in 59:60){
  temp_root <- subset(all_deco, all_deco$ID == root_IDs[i])
  temp2 <- temp_root %>% arrange(TOE)
  temp2$diff <- 0
  for(m in 2:nrow(temp2)){
  temp2$diff[m] <- temp2$length[m] - temp2$length[m-1]
  }
  temp3 <- subset(temp2, temp2$diff < 0.3)
  temp4 <- subset(temp3, temp3$diff > 0)
  temp4 <- temp4 %>% arrange(TOE)
  for(n in 2:nrow(temp4)){
    temp4$diff[n] <- temp4$length[n] - temp4$length[n-1]
  }
  temp5 <- subset(temp4, temp4$diff > 0)
  temp5 <- temp5 %>% arrange(TOE)
  for(o in 2:nrow(temp5)){
    temp5$diff[o] <- temp5$length[o] - temp5$length[o-1]
  }
  temp6 <- subset(temp5, temp5$diff > 0)
  double_cur <- rbind(double_cur, temp6)
}

for(i in 62:86){
  temp_root <- subset(all_deco, all_deco$ID == root_IDs[i])
  temp2 <- temp_root %>% arrange(TOE)
  temp2$diff <- 0
  for(m in 2:nrow(temp2)){
  temp2$diff[m] <- temp2$length[m] - temp2$length[m-1]
  }
  temp3 <- subset(temp2, temp2$diff < 0.3)
  temp4 <- subset(temp3, temp3$diff > 0)
  temp4 <- temp4 %>% arrange(TOE)
  for(n in 2:nrow(temp4)){
    temp4$diff[n] <- temp4$length[n] - temp4$length[n-1]
  }
  temp5 <- subset(temp4, temp4$diff > 0)
  temp5 <- temp5 %>% arrange(TOE)
  for(o in 2:nrow(temp5)){
    temp5$diff[o] <- temp5$length[o] - temp5$length[o-1]
  }
  temp6 <- subset(temp5, temp5$diff > 0)
  double_cur <- rbind(double_cur, temp6)
}

unique(double_cur$ID)
##  [1] "plate1_root_0"  "plate1_root_1"  "plate1_root_10" "plate1_root_11"
##  [5] "plate1_root_12" "plate1_root_13" "plate1_root_14" "plate1_root_15"
##  [9] "plate1_root_16" "plate1_root_17" "plate1_root_18" "plate1_root_19"
## [13] "plate1_root_2"  "plate1_root_20" "plate1_root_21" "plate1_root_22"
## [17] "plate1_root_23" "plate1_root_24" "plate1_root_25" "plate1_root_3" 
## [21] "plate1_root_4"  "plate1_root_5"  "plate1_root_6"  "plate1_root_7" 
## [25] "plate1_root_8"  "plate1_root_9"  "plate2_root_0"  "plate2_root_1" 
## [29] "plate2_root_10" "plate2_root_11" "plate2_root_12" "plate2_root_13"
## [33] "plate2_root_14" "plate2_root_15" "plate2_root_16" "plate2_root_17"
## [37] "plate2_root_18" "plate2_root_19" "plate2_root_2"  "plate2_root_20"
## [41] "plate2_root_21" "plate2_root_22" "plate2_root_23" "plate2_root_24"
## [45] "plate2_root_25" "plate2_root_3"  "plate2_root_4"  "plate2_root_5" 
## [49] "plate2_root_6"  "plate2_root_7"  "plate2_root_8"  "plate2_root_9" 
## [53] "plate3_root_0"  "plate3_root_10" "plate3_root_11" "plate3_root_12"
## [57] "plate3_root_14" "plate3_root_15" "plate3_root_17" "plate3_root_18"
## [61] "plate3_root_19" "plate3_root_2"  "plate3_root_3"  "plate3_root_4" 
## [65] "plate3_root_5"  "plate3_root_6"  "plate3_root_7"  "plate3_root_8" 
## [69] "plate3_root_9"  "plate4_root_0"  "plate4_root_1"  "plate4_root_10"
## [73] "plate4_root_11" "plate4_root_12" "plate4_root_13" "plate4_root_2" 
## [77] "plate4_root_3"  "plate4_root_4"  "plate4_root_5"  "plate4_root_6" 
## [81] "plate4_root_7"  "plate4_root_8"  "plate4_root_9"
double_cur
root_lgraph <- ggplot(data=double_cur, aes(x= TOE, y=length, group = ID, color = plate)) 
root_lgraph <- root_lgraph + geom_line(alpha = 0.1) 
#root_lgraph <- root_lgraph + stat_summary(fun.data = mean_se, geom="ribbon", linetype=0, aes(group=plate), alpha=0.3) + stat_summary(fun=mean, aes(group= plate),  size=0.7, geom="line", linetype = "dashed")
root_lgraph <- root_lgraph + ylab("Root Length (cm)") + xlab("Minutes After Stress")
root_lgraph

ok - it seems that there are still roots beyond rescue in this dataset - let’s look at them again:

PL1 <- subset(double_cur, double_cur$plate == "plate1")
PL2 <- subset(double_cur, double_cur$plate == "plate2")
PL3 <- subset(double_cur, double_cur$plate == "plate3")
PL4 <- subset(double_cur, double_cur$plate == "plate4")

PL1Col <- subset(PL1, PL1$genotype == "Col-0")
PL1C24 <- subset(PL1, PL1$genotype == "C24")
PL2Col <- subset(PL2, PL2$genotype == "Col-0")
PL2C24 <- subset(PL2, PL2$genotype == "C24")
PL3Col <- subset(PL3, PL3$genotype == "Col-0")
PL3C24 <- subset(PL3, PL3$genotype == "C24")
PL4Col <- subset(PL4, PL4$genotype == "Col-0")
PL4C24 <- subset(PL4, PL4$genotype == "C24")
PL4C24
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
Root_graph <- ggplot(data=PL1Col, aes(x= TOE, y=length, group = ID)) 
Root_graph <- Root_graph + geom_line(alpha = 0.1) 
Root_graph <- Root_graph + ylab("Root length (cm)") + xlab("Time (minutes)")
ggplotly(Root_graph)
unique(PL1Col$ID)
##  [1] "plate1_root_14" "plate1_root_15" "plate1_root_16" "plate1_root_17"
##  [5] "plate1_root_18" "plate1_root_19" "plate1_root_20" "plate1_root_21"
##  [9] "plate1_root_22" "plate1_root_23" "plate1_root_24" "plate1_root_25"
get_lost_temp <- c("plate1_root_24")
PL1ColClean <- subset(PL1Col, !(PL1Col$ID %in% get_lost_temp))
Root_graph <- ggplot(data=PL1ColClean, aes(x= TOE, y=length, group = ID)) 
Root_graph <- Root_graph + geom_line(alpha = 0.1) 
Root_graph <- Root_graph + ylab("Root length (cm)") + xlab("Time (minutes)")
ggplotly(Root_graph)
Root_graph <- ggplot(data=PL1C24, aes(x= TOE, y=length, group = ID)) 
Root_graph <- Root_graph + geom_line(alpha = 0.1) 
Root_graph <- Root_graph + ylab("Root length (cm)") + xlab("Time (minutes)")
ggplotly(Root_graph)
unique(PL1C24$ID)
##  [1] "plate1_root_0"  "plate1_root_1"  "plate1_root_10" "plate1_root_11"
##  [5] "plate1_root_12" "plate1_root_13" "plate1_root_2"  "plate1_root_3" 
##  [9] "plate1_root_4"  "plate1_root_5"  "plate1_root_6"  "plate1_root_7" 
## [13] "plate1_root_8"  "plate1_root_9"
get_lost_temp <- c("plate1_root_10", "plate1_root_11", "plate1_root_5", "plate1_root_0", "plate1_root_8", "plate1_root_4", "plate1_root_3")
PL1C24Clean <- subset(PL1C24, !(PL1C24$ID %in% get_lost_temp))
Root_graph <- ggplot(data=PL1C24Clean, aes(x= TOE, y=length, group = ID)) 
Root_graph <- Root_graph + geom_line(alpha = 0.1) 
Root_graph <- Root_graph + ylab("Root length (cm)") + xlab("Time (minutes)")
ggplotly(Root_graph)
Root_graph <- ggplot(data=PL2Col, aes(x= TOE, y=length, group = ID)) 
Root_graph <- Root_graph + geom_line(alpha = 0.1) 
Root_graph <- Root_graph + ylab("Root length (cm)") + xlab("Time (minutes)")
ggplotly(Root_graph)
unique(PL2Col$ID)
##  [1] "plate2_root_0"  "plate2_root_1"  "plate2_root_10" "plate2_root_2" 
##  [5] "plate2_root_3"  "plate2_root_4"  "plate2_root_5"  "plate2_root_6" 
##  [9] "plate2_root_7"  "plate2_root_8"  "plate2_root_9"
get_lost_temp <- c("plate2_root_0", "plate2_root_3", "plate2_root_7", "plate2_root_9")
PL2ColClean <- subset(PL2Col, !(PL2Col$ID %in% get_lost_temp))
Root_graph <- ggplot(data=PL2ColClean, aes(x= TOE, y=length, group = ID)) 
Root_graph <- Root_graph + geom_line(alpha = 0.1) 
Root_graph <- Root_graph + ylab("Root length (cm)") + xlab("Time (minutes)")
ggplotly(Root_graph)
Root_graph <- ggplot(data=PL2C24, aes(x= TOE, y=length, group = ID)) 
Root_graph <- Root_graph + geom_line(alpha = 0.1) 
Root_graph <- Root_graph + ylab("Root length (cm)") + xlab("Time (minutes)")
ggplotly(Root_graph)
unique(PL2C24$ID)
##  [1] "plate2_root_11" "plate2_root_12" "plate2_root_13" "plate2_root_14"
##  [5] "plate2_root_15" "plate2_root_16" "plate2_root_17" "plate2_root_18"
##  [9] "plate2_root_19" "plate2_root_20" "plate2_root_21" "plate2_root_22"
## [13] "plate2_root_23" "plate2_root_24" "plate2_root_25"
get_lost_temp <- c("plate2_root_12", "plate2_root_22", "plate2_root_23")
PL2C24Clean <- subset(PL2C24, !(PL2C24$ID %in% get_lost_temp))
Root_graph <- ggplot(data=PL2C24Clean, aes(x= TOE, y=length, group = ID)) 
Root_graph <- Root_graph + geom_line(alpha = 0.1) 
Root_graph <- Root_graph + ylab("Root length (cm)") + xlab("Time (minutes)")
ggplotly(Root_graph)
Root_graph <- ggplot(data=PL3Col, aes(x= TOE, y=length, group = ID)) 
Root_graph <- Root_graph + geom_line(alpha = 0.1) 
Root_graph <- Root_graph + ylab("Root length (cm)") + xlab("Time (minutes)")
ggplotly(Root_graph)
unique(PL3Col$ID)
## [1] "plate3_root_12" "plate3_root_14" "plate3_root_15" "plate3_root_17"
## [5] "plate3_root_18" "plate3_root_19"
get_lost_temp <- c("plate3_root_18", "plate3_root_19", "plate3_root_14")
PL3ColClean <- subset(PL3Col, !(PL3Col$ID %in% get_lost_temp))
Root_graph <- ggplot(data=PL3ColClean, aes(x= TOE, y=length, group = ID)) 
Root_graph <- Root_graph + geom_line(alpha = 0.1) 
Root_graph <- Root_graph + ylab("Root length (cm)") + xlab("Time (minutes)")
ggplotly(Root_graph)
Root_graph <- ggplot(data=PL3C24, aes(x= TOE, y=length, group = ID)) 
Root_graph <- Root_graph + geom_line(alpha = 0.1) 
Root_graph <- Root_graph + ylab("Root length (cm)") + xlab("Time (minutes)")
ggplotly(Root_graph)
unique(PL3C24$ID)
##  [1] "plate3_root_0"  "plate3_root_10" "plate3_root_11" "plate3_root_2" 
##  [5] "plate3_root_3"  "plate3_root_4"  "plate3_root_5"  "plate3_root_6" 
##  [9] "plate3_root_7"  "plate3_root_8"  "plate3_root_9"
get_lost_temp <- c("plate3_root_5", "plate3_root_9", "plate3_root_2", "plate3_root_8", "plate3_root_7")
PL3C24Clean <- subset(PL3C24, !(PL3C24$ID %in% get_lost_temp))
Root_graph <- ggplot(data=PL3C24Clean, aes(x= TOE, y=length, group = ID)) 
Root_graph <- Root_graph + geom_line(alpha = 0.1) 
Root_graph <- Root_graph + ylab("Root length (cm)") + xlab("Time (minutes)")
ggplotly(Root_graph)
Root_graph <- ggplot(data=PL4Col, aes(x= TOE, y=length, group = ID)) 
Root_graph <- Root_graph + geom_line(alpha = 0.1) 
Root_graph <- Root_graph + ylab("Root length (cm)") + xlab("Time (minutes)")
ggplotly(Root_graph)
unique(PL4Col$ID)
## [1] "plate4_root_10" "plate4_root_11" "plate4_root_12" "plate4_root_13"
## [5] "plate4_root_9"
get_lost_temp <- c("plate4_root_12", "plate4_root_13")
PL4ColClean <- subset(PL4Col, !(PL4Col$ID %in% get_lost_temp))
Root_graph <- ggplot(data=PL4ColClean, aes(x= TOE, y=length, group = ID)) 
Root_graph <- Root_graph + geom_line(alpha = 0.1) 
Root_graph <- Root_graph + ylab("Root length (cm)") + xlab("Time (minutes)")
ggplotly(Root_graph)
Root_graph <- ggplot(data=PL4C24, aes(x= TOE, y=length, group = ID)) 
Root_graph <- Root_graph + geom_line(alpha = 0.1) 
Root_graph <- Root_graph + ylab("Root length (cm)") + xlab("Time (minutes)")
ggplotly(Root_graph)
unique(PL4C24$ID)
## [1] "plate4_root_0" "plate4_root_1" "plate4_root_2" "plate4_root_3"
## [5] "plate4_root_4" "plate4_root_5" "plate4_root_6" "plate4_root_7"
## [9] "plate4_root_8"
get_lost_temp <- c("plate4_root_0", "plate4_root_4")
PL4C24Clean <- subset(PL4C24, !(PL4C24$ID %in% get_lost_temp))
Root_graph <- ggplot(data=PL4C24Clean, aes(x= TOE, y=length, group = ID)) 
Root_graph <- Root_graph + geom_line(alpha = 0.1) 
Root_graph <- Root_graph + ylab("Root length (cm)") + xlab("Time (minutes)")
ggplotly(Root_graph)

let’s combine all of the get_lost samples - and remove them from the data:

get_lost <- c("plate1_root_24", "plate1_root_10", "plate1_root_11", "plate1_root_5", "plate1_root_0", "plate1_root_8", "plate1_root_4", "plate1_root_3",
              "plate2_root_0", "plate2_root_3", "plate2_root_7", "plate2_root_9", "plate2_root_12", "plate2_root_22", "plate2_root_23", 
              "plate3_root_18", "plate3_root_19", "plate3_root_14", "plate3_root_5", "plate3_root_9", "plate3_root_2", "plate3_root_8", "plate3_root_7", 
              "plate3_root_10", "plate4_root_12", "plate4_root_13", "plate4_root_0", "plate4_root_4", "plate4_root_10")
triple_cur_data <- subset(double_cur, !(double_cur$ID %in% get_lost))
triple_cur_data
colnames(triple_cur_data)
##  [1] "ID"                    "root_name"             "plate"                
##  [4] "image"                 "root"                  "length"               
##  [7] "surface"               "volume"                "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"                  "time"                 
## [25] "month"                 "day"                   "hour"                 
## [28] "min"                   "TOE"                   "root.number"          
## [31] "genotype"              "treatment"             "diff"
root_lgraph <- ggplot(data=triple_cur_data, aes(x= TOE, y=length, group = ID, color = genotype)) 
root_lgraph <- root_lgraph + geom_line(alpha = 0.1) 
root_lgraph <- root_lgraph + facet_wrap(~ treatment)
#root_lgraph <- root_lgraph + stat_summary(fun=mean, aes(group= genotype),  size=0.7, geom="line", linetype = "dashed")
root_lgraph <- root_lgraph + ylab("Root Length (cm)") + xlab("Minutes After Stress")
root_lgraph

This looks good - but as soon as I start to add average / median - it gets messy - probably since we dont have many timepoints shared that have ALL measurements. Maybe its an overkill at this point to image every 20 minutes.

colnames(triple_cur_data)
##  [1] "ID"                    "root_name"             "plate"                
##  [4] "image"                 "root"                  "length"               
##  [7] "surface"               "volume"                "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"                  "time"                 
## [25] "month"                 "day"                   "hour"                 
## [28] "min"                   "TOE"                   "root.number"          
## [31] "genotype"              "treatment"             "diff"
root_lgraph <- ggplot(data=triple_cur_data, aes(x= TOE, y=length, group = ID, color = genotype)) 
root_lgraph <- root_lgraph + geom_line(alpha = 0.1) 
root_lgraph <- root_lgraph + facet_wrap(~ treatment)
root_lgraph <- root_lgraph + stat_summary(fun=mean, aes(group= genotype),  size=0.7, geom="line", linetype = "dashed")
root_lgraph <- root_lgraph + ylab("Root Length (cm)") + xlab("Minutes After Stress")
root_lgraph

Since we are missing quite some timepoints now - how about we calculate a spline for each indivdual root - and THEN run all the growth rates and stats on the spline fitted data.

Need to know about spline fitting - check out this paper by Perperoglou et al., 2019

# let's isolate one root ID:
unique(triple_cur_data$ID)[1]
## [1] "plate1_root_1"
temp <- subset(triple_cur_data, triple_cur_data$ID == "plate1_root_1")
temp
# plot the spline - df 10 chosen based on the best fit for such a long interval to fit our growth most optimally:
plot.spl <- with(temp, smooth.spline(TOE, length, df = 10))
## Warning in smooth.spline(TOE, length, df = 10): not using invalid df; must have
## 1 < df <= n := #{unique x} = 9
plot.spl$fit
## $knot
##  [1] 0.00000000 0.00000000 0.00000000 0.00000000 0.01612253 0.17775091
##  [7] 0.27448609 0.42765014 0.65336558 0.75816203 0.87101975 1.00000000
## [13] 1.00000000 1.00000000 1.00000000
## 
## $nk
## [1] 11
## 
## $min
## [1] 19
## 
## $range
## [1] 2481
## 
## $coef
##  [1] 0.9530551 0.9550735 0.9773271 1.0116915 1.0632128 1.1227576 1.1833115
##  [8] 1.2388193 1.2822163 1.3124933 1.3286410
## 
## attr(,"class")
## [1] "smooth.spline.fit"
# let's see how well our spline fits the observed data:
plot(length ~ TOE, data = temp)
lines(plot.spl, col = "blue")

# let's isolate the predicted spline variables 
# create timeline of interest:
timeline <- seq(0, 4240, 20)
timeline
##   [1]    0   20   40   60   80  100  120  140  160  180  200  220  240  260  280
##  [16]  300  320  340  360  380  400  420  440  460  480  500  520  540  560  580
##  [31]  600  620  640  660  680  700  720  740  760  780  800  820  840  860  880
##  [46]  900  920  940  960  980 1000 1020 1040 1060 1080 1100 1120 1140 1160 1180
##  [61] 1200 1220 1240 1260 1280 1300 1320 1340 1360 1380 1400 1420 1440 1460 1480
##  [76] 1500 1520 1540 1560 1580 1600 1620 1640 1660 1680 1700 1720 1740 1760 1780
##  [91] 1800 1820 1840 1860 1880 1900 1920 1940 1960 1980 2000 2020 2040 2060 2080
## [106] 2100 2120 2140 2160 2180 2200 2220 2240 2260 2280 2300 2320 2340 2360 2380
## [121] 2400 2420 2440 2460 2480 2500 2520 2540 2560 2580 2600 2620 2640 2660 2680
## [136] 2700 2720 2740 2760 2780 2800 2820 2840 2860 2880 2900 2920 2940 2960 2980
## [151] 3000 3020 3040 3060 3080 3100 3120 3140 3160 3180 3200 3220 3240 3260 3280
## [166] 3300 3320 3340 3360 3380 3400 3420 3440 3460 3480 3500 3520 3540 3560 3580
## [181] 3600 3620 3640 3660 3680 3700 3720 3740 3760 3780 3800 3820 3840 3860 3880
## [196] 3900 3920 3940 3960 3980 4000 4020 4040 4060 4080 4100 4120 4140 4160 4180
## [211] 4200 4220 4240
min(triple_cur_data$TOE)
## [1] 19
max(triple_cur_data$TOE)
## [1] 3062
# plot predicted variables with the observed variables:
plot(length ~ TOE, data = temp)
lines(plot.spl, col = "blue")
lines(predict(plot.spl, timeline), col="red")

# save predicted variables in the separate data frame
names <- c(text="ID", "genotype", "treatment", "TOE", "length.spl")
spline_data <- data.frame()
for (k in names) spline_data[[k]] <- as.character()
spline_data
pred_temp <- predict(plot.spl, timeline)


# make empty dataframe
spline_data[1:213,4] <- pred_temp$x
spline_data[1:213,5] <- pred_temp$y
spline_data[1:213,1] <- temp$ID[1]
spline_data[1:213,2] <- temp$genotype[1]
spline_data[1:213,3] <- temp$treatment[1]

spline_data

now - let’s save this into a final_spline data and let’s start looping throughout the entire experiment:

final_spline <- spline_data
min(triple_cur_data$TOE)
## [1] 19
max(triple_cur_data$TOE)
## [1] 3062
all_roots <- unique(triple_cur_data$ID)
all_roots
##  [1] "plate1_root_1"  "plate1_root_12" "plate1_root_13" "plate1_root_14"
##  [5] "plate1_root_15" "plate1_root_16" "plate1_root_17" "plate1_root_18"
##  [9] "plate1_root_19" "plate1_root_2"  "plate1_root_20" "plate1_root_21"
## [13] "plate1_root_22" "plate1_root_23" "plate1_root_25" "plate1_root_6" 
## [17] "plate1_root_7"  "plate1_root_9"  "plate2_root_1"  "plate2_root_10"
## [21] "plate2_root_11" "plate2_root_13" "plate2_root_14" "plate2_root_15"
## [25] "plate2_root_16" "plate2_root_17" "plate2_root_18" "plate2_root_19"
## [29] "plate2_root_2"  "plate2_root_20" "plate2_root_21" "plate2_root_24"
## [33] "plate2_root_25" "plate2_root_4"  "plate2_root_5"  "plate2_root_6" 
## [37] "plate2_root_8"  "plate3_root_0"  "plate3_root_11" "plate3_root_12"
## [41] "plate3_root_15" "plate3_root_17" "plate3_root_3"  "plate3_root_4" 
## [45] "plate3_root_6"  "plate4_root_1"  "plate4_root_11" "plate4_root_2" 
## [49] "plate4_root_3"  "plate4_root_5"  "plate4_root_6"  "plate4_root_7" 
## [53] "plate4_root_8"  "plate4_root_9"
length(all_roots)
## [1] 54
for(i in 2:54){
  temp <- subset(triple_cur_data, triple_cur_data$ID == all_roots[i])
  plot.spl <- with(temp, smooth.spline(TOE, length, df = 10))
  pred_temp <- predict(plot.spl, timeline)
  spline_data[1:213,4] <- pred_temp$x
  spline_data[1:213,5] <- pred_temp$y
  spline_data[1:213,1] <- temp$ID[1]
  spline_data[1:213,2] <- temp$genotype[1]
  spline_data[1:213,3] <- temp$treatment[1]
  final_spline <- rbind(final_spline, spline_data)
}
## Warning in smooth.spline(TOE, length, df = 10): not using invalid df; must have
## 1 < df <= n := #{unique x} = 7
## Warning in smooth.spline(TOE, length, df = 10): not using invalid df; must have
## 1 < df <= n := #{unique x} = 6
## Warning in smooth.spline(TOE, length, df = 10): not using invalid df; must have
## 1 < df <= n := #{unique x} = 8
## Warning in smooth.spline(TOE, length, df = 10): not using invalid df; must have
## 1 < df <= n := #{unique x} = 9

## Warning in smooth.spline(TOE, length, df = 10): not using invalid df; must have
## 1 < df <= n := #{unique x} = 9
## Warning in smooth.spline(TOE, length, df = 10): not using invalid df; must have
## 1 < df <= n := #{unique x} = 8
## Warning in smooth.spline(TOE, length, df = 10): not using invalid df; must have
## 1 < df <= n := #{unique x} = 7
## Warning in smooth.spline(TOE, length, df = 10): not using invalid df; must have
## 1 < df <= n := #{unique x} = 9
## Warning in smooth.spline(TOE, length, df = 10): not using invalid df; must have
## 1 < df <= n := #{unique x} = 7
## Warning in smooth.spline(TOE, length, df = 10): not using invalid df; must have
## 1 < df <= n := #{unique x} = 9
## Warning in smooth.spline(TOE, length, df = 10): not using invalid df; must have
## 1 < df <= n := #{unique x} = 8
## Warning in smooth.spline(TOE, length, df = 10): not using invalid df; must have
## 1 < df <= n := #{unique x} = 9
## Warning in smooth.spline(TOE, length, df = 10): not using invalid df; must have
## 1 < df <= n := #{unique x} = 6
i
## [1] 54
temp
final_spline$TOE <- as.numeric(as.character(final_spline$TOE))
final_spline$length.spl <- as.numeric(as.character(final_spline$length.spl))
unique(final_spline$ID)
##  [1] "plate1_root_1"  "plate1_root_12" "plate1_root_13" "plate1_root_14"
##  [5] "plate1_root_15" "plate1_root_16" "plate1_root_17" "plate1_root_18"
##  [9] "plate1_root_19" "plate1_root_2"  "plate1_root_20" "plate1_root_21"
## [13] "plate1_root_22" "plate1_root_23" "plate1_root_25" "plate1_root_6" 
## [17] "plate1_root_7"  "plate1_root_9"  "plate2_root_1"  "plate2_root_10"
## [21] "plate2_root_11" "plate2_root_13" "plate2_root_14" "plate2_root_15"
## [25] "plate2_root_16" "plate2_root_17" "plate2_root_18" "plate2_root_19"
## [29] "plate2_root_2"  "plate2_root_20" "plate2_root_21" "plate2_root_24"
## [33] "plate2_root_25" "plate2_root_4"  "plate2_root_5"  "plate2_root_6" 
## [37] "plate2_root_8"  "plate3_root_0"  "plate3_root_11" "plate3_root_12"
## [41] "plate3_root_15" "plate3_root_17" "plate3_root_3"  "plate3_root_4" 
## [45] "plate3_root_6"  "plate4_root_1"  "plate4_root_11" "plate4_root_2" 
## [49] "plate4_root_3"  "plate4_root_5"  "plate4_root_6"  "plate4_root_7" 
## [53] "plate4_root_8"  "plate4_root_9"

Cool - NOW let’s try to compare the averages:

library(ggpubr)

spl_root_lgraph <- ggplot(data=final_spline, aes(x= TOE, y=length.spl, group = ID, color = genotype)) 
spl_root_lgraph <- spl_root_lgraph + geom_line(alpha = 0.1) 
spl_root_lgraph <- spl_root_lgraph + facet_wrap(~ treatment)
spl_root_lgraph <- spl_root_lgraph + stat_summary(fun.data = mean_se, geom="ribbon", linetype=0, aes(group= genotype), alpha=0.3)
spl_root_lgraph <- spl_root_lgraph + stat_summary(fun=mean, aes(group= genotype),  size=0.7, geom="line", linetype = "dashed")
#spl_root_lgraph <- spl_root_lgraph + stat_compare_means(aes(group = genotype), label = "p.signif", method = "t.test", hide.ns = T)
spl_root_lgraph <- spl_root_lgraph + ylab("Root Length (cm)") + xlab("Minutes After Stress")
spl_root_lgraph

now - that’s what I call an informative graph! Great! Let’s just change the x-axis to factor and calculate the significant differences:

final_spline$TOE.factor <- as.factor(final_spline$TOE)

spl_root_lgraph_sig <- ggplot(data=final_spline, aes(x= TOE.factor, y=length.spl, group = ID, color = genotype)) 
spl_root_lgraph_sig <- spl_root_lgraph_sig + geom_line(alpha = 0.1) 
spl_root_lgraph_sig <- spl_root_lgraph_sig + facet_wrap(~ treatment)
spl_root_lgraph_sig <- spl_root_lgraph_sig + stat_summary(fun.data = mean_se, geom="ribbon", linetype=0, aes(group= genotype), alpha=0.3)
spl_root_lgraph_sig <- spl_root_lgraph_sig + stat_summary(fun=mean, aes(group= genotype),  size=0.7, geom="line", linetype = "dashed")
spl_root_lgraph_sig <- spl_root_lgraph_sig + stat_compare_means(aes(group = genotype), label = "p.signif", method = "t.test", hide.ns = T)
spl_root_lgraph_sig <- spl_root_lgraph_sig + ylab("Root Length (cm)") + xlab("Minutes After Stress")
spl_root_lgraph_sig

Not the most beautiful looking graph with the scale like this - but at least we know that the root length is significant between the genotypes at ALL timepoints.

Growth rate calculations

Cool - now we have the individual curated points - we can calculate the growth rates.

let’s calculate the growth rate for each 20 minutes based on a shifting HOUR timeline to compare them between genotypes and treatments

(P.S. YES - I know 0 mM NaCl is showing lower growth than 75 mM NaCl - I suspect that 0 and 75 mM NaCl are swapped for some reason - I dont know what happened but looking at the pictures - the plants at 0mM marked plate are indeed smaller - so there was defo some confusion as to what plate is what - but since this pipeline is just to describe the GENERAL procedure of SPIRO data analysis - we will let that one slip).

So - let’s generate a new TOE - but let’s mae it one hour shorter (otherwise we wont have enough data-points for the last timepoint)

timeline
##   [1]    0   20   40   60   80  100  120  140  160  180  200  220  240  260  280
##  [16]  300  320  340  360  380  400  420  440  460  480  500  520  540  560  580
##  [31]  600  620  640  660  680  700  720  740  760  780  800  820  840  860  880
##  [46]  900  920  940  960  980 1000 1020 1040 1060 1080 1100 1120 1140 1160 1180
##  [61] 1200 1220 1240 1260 1280 1300 1320 1340 1360 1380 1400 1420 1440 1460 1480
##  [76] 1500 1520 1540 1560 1580 1600 1620 1640 1660 1680 1700 1720 1740 1760 1780
##  [91] 1800 1820 1840 1860 1880 1900 1920 1940 1960 1980 2000 2020 2040 2060 2080
## [106] 2100 2120 2140 2160 2180 2200 2220 2240 2260 2280 2300 2320 2340 2360 2380
## [121] 2400 2420 2440 2460 2480 2500 2520 2540 2560 2580 2600 2620 2640 2660 2680
## [136] 2700 2720 2740 2760 2780 2800 2820 2840 2860 2880 2900 2920 2940 2960 2980
## [151] 3000 3020 3040 3060 3080 3100 3120 3140 3160 3180 3200 3220 3240 3260 3280
## [166] 3300 3320 3340 3360 3380 3400 3420 3440 3460 3480 3500 3520 3540 3560 3580
## [181] 3600 3620 3640 3660 3680 3700 3720 3740 3760 3780 3800 3820 3840 3860 3880
## [196] 3900 3920 3940 3960 3980 4000 4020 4040 4060 4080 4100 4120 4140 4160 4180
## [211] 4200 4220 4240
length(timeline)
## [1] 213
growth_timeline <- timeline[1:211]

let’s isolate again one root and calculate the growth rate for the 1st hour:

temp <- subset(final_spline, final_spline$ID == all_roots[1])
temp
temp_now <- subset(temp, temp$TOE < 60)
temp_now
plot(temp_now$length.spl ~ temp_now$TOE) + abline(lm(temp_now$length.spl ~ temp_now$TOE))

## integer(0)
model_now <- lm(temp_now$length.spl ~ temp_now$TOE)
summary(model_now)
## 
## Call:
## lm(formula = temp_now$length.spl ~ temp_now$TOE)
## 
## Residuals:
##          1          2          3 
## -1.015e-13  2.029e-13 -1.015e-13 
## 
## Coefficients:
##               Estimate Std. Error   t value Pr(>|t|)    
## (Intercept)  9.502e-01  2.269e-13 4.188e+12 1.52e-13 ***
## temp_now$TOE 1.514e-04  8.788e-15 1.723e+10 3.70e-11 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.486e-13 on 1 degrees of freedom
## Multiple R-squared:      1,  Adjusted R-squared:      1 
## F-statistic: 2.968e+20 on 1 and 1 DF,  p-value: 3.696e-11
GR <- model_now$coefficients[2]

now let’s save this in an empty dataframe:

names <- c(text="ID", "genotype", "treatment", "TOE", "GR")
growth_data <- data.frame()
for (k in names) growth_data[[k]] <- as.character()
growth_data
growth_data[1,1] <- temp_now$ID[1]
growth_data[1,2] <- temp_now$genotype[1]
growth_data[1,3] <- temp_now$treatment[1]
growth_data[1,4] <- min(temp_now$TOE)
growth_data[1,5] <- GR
growth_data

Let’s circle through ALL timepoints within this one genotype:

for(t in 1:length(growth_timeline)){
  min = (t-1)*20
  max = min + 60
  temp_now <- subset(temp, temp$TOE < max)
  temp_now <- subset(temp_now, temp_now$TOE > min)
  model_now <- lm(temp_now$length.spl ~ temp_now$TOE)
  growth_data[t,1] <- temp_now$ID[1]
  growth_data[t,2] <- temp_now$genotype[1]
  growth_data[t,3] <- temp_now$treatment[1]
  growth_data[t,4] <- min(temp_now$TOE)
  growth_data[t,5] <- model_now$coefficients[2]
}

growth_data

OK - now let’s loop it for ALL of the roots within this experiment:

counter = 1

for(r in 1:length(all_roots)){
  temp <- subset(final_spline, final_spline$ID == all_roots[r])
  for(t in 1:length(growth_timeline)){
    min = (t-1)*20
    max = min + 60
    temp_now <- subset(temp, temp$TOE < max)
    temp_now <- subset(temp_now, temp_now$TOE > min)
    model_now <- lm(temp_now$length.spl ~ temp_now$TOE)
    growth_data[counter,1] <- temp_now$ID[1]
    growth_data[counter,2] <- temp_now$genotype[1]
    growth_data[counter,3] <- temp_now$treatment[1]
    growth_data[counter,4] <- min(temp_now$TOE)
    growth_data[counter,5] <- model_now$coefficients[2]
    counter <- counter + 1
  }
}

growth_data

Cool - now lets plot our growth rates over time - similar to what we did with root length:

growth_data$GR <- as.numeric(as.character(growth_data$GR))
growth_data$TOE <- as.numeric(as.character(growth_data$TOE))
# growth_data$TOE.fac <- as.factor(growth_data$TOE)

rootGR_lgraph <- ggplot(data=growth_data, aes(x= TOE, y=GR, group = ID, color = genotype)) 
rootGR_lgraph <- rootGR_lgraph + geom_line(alpha = 0.1) 
rootGR_lgraph <- rootGR_lgraph + facet_wrap(~ treatment)
rootGR_lgraph <- rootGR_lgraph + stat_summary(fun.data = mean_se, geom="ribbon", linetype=0, aes(group= genotype), alpha=0.3)
rootGR_lgraph <- rootGR_lgraph + stat_summary(fun=mean, aes(group= genotype),  size=0.7, geom="line", linetype = "dashed")
rootGR_lgraph <- rootGR_lgraph + ylim(0, 0.0007) + xlim(0, 3000)
#rootGR_lgraph <- rootGR_lgraph + stat_compare_means(aes(group = genotype), label = "p.signif", method = "t.test", hide.ns = T)
rootGR_lgraph <- rootGR_lgraph + ylab("Root Growth Rate (cm / min)") + xlab("Minutes After Stress")
rootGR_lgraph
## Warning: Removed 3716 rows containing non-finite values (stat_summary).
## Removed 3716 rows containing non-finite values (stat_summary).
## Warning: Removed 3493 row(s) containing missing values (geom_path).

Now - let’s calculate the RELATIVE Growth Rate for both Col-0 and C24 for both salt stress treatments.

First - let’s calculate average GR per TOE per Genotype per Treatment:

#install.packages("doBy")
library(doBy)
## 
## Attaching package: 'doBy'
## The following object is masked from 'package:dplyr':
## 
##     order_by
sum_growth <- summaryBy(data = growth_data, GR ~ treatment + genotype + TOE)
sum_growth

Let’s keep only the control GR from this mean calculations:

sum_C <- subset(sum_growth, sum_growth$treatment == "0 mM NaCl Spray" | sum_growth$treatment == "0 mM NaCl Transfer")
# make sure its mean under Control
colnames(sum_C)[4] <- "GR.mean.Control"
sum_C

Since we have two different treatment TYPES (Spray vs. Transfer) - we should add another identifier of treatment - so we can compare controls to their respective treatment type.

sum_C$treatment.type <- sum_C$treatment
sum_C$treatment.type <- gsub("0 mM NaCl ", "", sum_C$treatment.type)
sum_C$treatment.type <- gsub("125 mM NaCl ", "", sum_C$treatment.type)
head(sum_C)
growth_data$treatment.type <- growth_data$treatment
growth_data$treatment.type <- gsub("0 mM NaCl ", "", growth_data$treatment.type)
growth_data$treatment.type <- gsub("125 mM NaCl ", "", growth_data$treatment.type)
head(growth_data)

now - let’s match our AVERAGE growth rate to our RAW growth_data by Genotype and TOE:

growth_data2 <- merge(growth_data, sum_C, by = c("TOE", "genotype", "treatment.type"), all=TRUE)
growth_data2

Let’s calculate relative growth rate by dividing GR / GR.mean.Control:

growth_data2$GRrel <- growth_data2$GR / growth_data2$GR.mean.Control
# we dont really need 0mM NaCl anymore - since it's average will be around 1
bye <- c("0 mM NaCl Spray", "0 mM NaCl Transfer")
growth_data2 <- subset(growth_data2, !(growth_data2$treatment.x %in% bye))
growth_data2

Now - let’s plot the relative growth rate:

I m not exactly sure why the t-test is not working for me here.

Rel_rootGR_lgraph <- ggplot(data=growth_data2, aes(x= TOE, y=GRrel, group = ID, color = genotype)) 
Rel_rootGR_lgraph <- Rel_rootGR_lgraph + geom_line(alpha = 0.1) 
Rel_rootGR_lgraph <- Rel_rootGR_lgraph + facet_wrap(~ treatment.type)
Rel_rootGR_lgraph <- Rel_rootGR_lgraph + stat_summary(fun.data = mean_se, geom="ribbon", linetype=0, aes(group= genotype), alpha=0.3)
Rel_rootGR_lgraph <- Rel_rootGR_lgraph + stat_summary(fun=mean, aes(group= genotype),  size=0.7, geom="line", linetype = "dashed")
Rel_rootGR_lgraph <- Rel_rootGR_lgraph + ylim(0, 2) + xlim(0, 3000)
#Rel_rootGR_lgraph <- Rel_rootGR_lgraph + stat_compare_means(aes(group = genotype), label = "p.signif", method = "t.test", hide.ns = T)
Rel_rootGR_lgraph <- Rel_rootGR_lgraph + ylab("Relative Root Growth Rate (fraction of control)") + xlab("Minutes After Stress")
Rel_rootGR_lgraph
## Warning: Removed 2150 rows containing non-finite values (stat_summary).
## Removed 2150 rows containing non-finite values (stat_summary).
## Warning: Removed 1923 row(s) containing missing values (geom_path).