This R Notebook is to analyze the EVT of the drought experiment that used AT homologous TDNA insertion lines. TheTDNA insertions are within homologous genes observed to be involved in drought response in Cowpea.

library("ggplot2")
library("reshape2")
library("cowplot")
library("ggpubr")
## 
## Attaching package: 'ggpubr'
## The following object is masked from 'package:cowplot':
## 
##     get_legend
list.files(pattern = ".csv")
## [1] "2023 soil confirmation experiment - Redo - EVT.csv"
EVT_redo <- read.csv("2023 soil confirmation experiment - Redo - EVT.csv")
EVT_redo$plant.id <- paste(EVT_redo$tray, EVT_redo$position)
EVT_redo$plant.id <- sub(" ", "_",EVT_redo$plant.id)
colnames(EVT_redo)
##  [1] "tray"      "position"  "treatment" "mutant"    "day.3"     "day.5"    
##  [7] "day.7"     "day.9"     "day.11"    "day.13"    "day.15"    "plant.id"
EVTr_selected <- EVT_redo[,c(12, 3:11)]
EVTr_selected
melt_evtr <- melt(EVTr_selected, id.vars = c("plant.id", "treatment", "mutant"))

colnames(melt_evtr)[4] <- "day"
colnames(melt_evtr)[5] <- "evapotranspiration"
melt_evtr
melt_evtr$day <- gsub("day.", "", melt_evtr$day)
melt_evtr$day <- as.numeric(melt_evtr$day)

# meltevt_neg <- subset(melt_evtr, melt_evtr$evapotranspiration < 0)
# meltevt_neg

#There are no negative EVT values in the data frame so nothing needs to be checked into further
melt_evtr$mutant <- gsub("m10", "CP.NPQ6-1", melt_evtr$mutant)
melt_evtr$mutant <- gsub("m11", "CP.NPQ6-2", melt_evtr$mutant)
melt_evtr$mutant <- gsub("m12", "CP.NPQ6-3", melt_evtr$mutant)
melt_evtr$mutant <- gsub("m13", "CP.NPQ6-4", melt_evtr$mutant)
melt_evtr$mutant <- gsub("m14", "CP.NPQ6-5", melt_evtr$mutant)
melt_evtr$mutant <- gsub("m1", "CP.EVT2-1", melt_evtr$mutant)
melt_evtr$mutant <- gsub("m2", "CP.EVT2-2", melt_evtr$mutant)
melt_evtr$mutant <- gsub("m3", "CP.EVT3-1", melt_evtr$mutant)
melt_evtr$mutant <- gsub("m4", "CP.EVT3-2", melt_evtr$mutant)
melt_evtr$mutant <- gsub("m5", "CP.EVT6-1", melt_evtr$mutant)
melt_evtr$mutant <- gsub("m6", "CP.EVT6-2", melt_evtr$mutant)
melt_evtr$mutant <- gsub("m7", "CP.EVT8", melt_evtr$mutant)
melt_evtr$mutant <- gsub("m8", "CP.GR4-1", melt_evtr$mutant)
melt_evtr$mutant <- gsub("m9", "CP.GR4-2", melt_evtr$mutant)

unique(melt_evtr$mutant)
##  [1] "Col-0"     "CP.EVT2-1" "CP.EVT2-2" "CP.EVT3-1" "CP.EVT3-2" "CP.EVT6-1"
##  [7] "CP.EVT6-2" "CP.EVT8"   "CP.GR4-1"  "CP.GR4-2"  "CP.NPQ6-1" "CP.NPQ6-2"
## [13] "CP.NPQ6-3" "CP.NPQ6-4" "CP.NPQ6-5"

#plotting EVT over time

melt_evtr$plant.id <- as.factor(melt_evtr$plant.id)

EVTr_over_time <- ggplot(data = melt_evtr, aes(x = day, y = evapotranspiration, group = plant.id, colour = treatment), na.rm = TRUE) + theme_classic() + ylim(0, NA)
EVTr_over_time <- EVTr_over_time + geom_line(alpha = 0.1)
EVTr_over_time <- EVTr_over_time + stat_summary(fun.data = mean_se, linetype = 0, aes(group = treatment), alpha = 0.3) + stat_summary(fun = mean, aes(group = treatment), linewidth = 0.7, geom = "line", linetype = "dashed")
EVTr_over_time <- EVTr_over_time + facet_wrap(~ treatment)
EVTr_over_time <- EVTr_over_time + ylab("Evapotranspiration (g)") + xlab("Day") + rremove("legend") +scale_color_manual(values=c("blue", "red"))
EVTr_over_time

EVTr_cd <- ggplot(data = melt_evtr, aes(x = day, y = evapotranspiration, group = plant.id, colour = treatment), na.rm = TRUE) + theme_classic() + ylim(0, NA)
EVTr_cd <- EVTr_cd + geom_line(alpha = 0.1)
EVTr_cd <- EVTr_cd + stat_summary(fun.data = mean_se, geom = "ribbon", linetype = 0, aes(group = treatment), alpha = 0.1) + stat_summary(fun = mean, aes(group = treatment), linewidth = 0.7, geom = "line", linetype = "dashed")
EVTr_cd <- EVTr_cd + stat_compare_means(aes(group = treatment), label = "p.signif", method = "t.test", hide.ns = TRUE)
EVTr_cd <- EVTr_cd + scale_color_manual(labels=c("Control", "Drought"), values=c("blue", "red"))
EVTr_cd <- EVTr_cd + ylab("Evapotranspiration (g)") + xlab("Day")
EVTr_cd

#By Genotype

EVTr_over_time_geno <- ggplot(data = melt_evtr, aes(x = day, y = evapotranspiration, group = plant.id, colour = treatment), na.rm = TRUE) + theme_classic() + ylim(0, NA)
EVTr_over_time_geno <- EVTr_over_time_geno + geom_line(alpha = 0.1)
EVTr_over_time_geno <- EVTr_over_time_geno + facet_wrap(~ mutant)
EVTr_over_time_geno <- EVTr_over_time_geno + stat_summary(fun.data = mean_se, linetype = 0, aes(group = treatment), alpha = 0.3) + stat_summary(fun = mean, aes(group = treatment), linewidth = 0.7, geom = "line", linetype = "dashed")
EVTr_over_time_geno <- EVTr_over_time_geno + stat_compare_means(aes(group = treatment), label = "p.signif", method = "t.test", hide.ns = FALSE, label.y=20)
EVTr_over_time_geno <- EVTr_over_time_geno + ylab("Evapotranspiration (g)") + xlab("Day") + rremove("legend") +scale_color_manual(values=c("blue", "red"))
EVTr_over_time_geno

# pdf("EVT_redo_CvD.pdf", 15, 10)
# plot(EVTr_cd)
# dev.off()
# 
# pdf("EVT_redo_over_time.pdf", 15, 10)
# plot(EVTr_over_time)
# dev.off()
# 
# pdf("EVT_redo_per_geno.pdf", 15, 10)
# plot(EVTr_over_time_geno)
# dev.off()

#Compare each genotype to Col-0

melt_evtr
length(unique(melt_evtr$mutant))
## [1] 15
Col_data <- subset(melt_evtr, melt_evtr$mutant == "Col-0")

Col1 <- Col_data
Col1$facet <- unique(melt_evtr$mutant)[1]
Col2 <- Col_data
Col2$facet <- unique(melt_evtr$mutant)[2]
Col3 <- Col_data
Col3$facet <- unique(melt_evtr$mutant)[3]
Col4 <- Col_data
Col4$facet <- unique(melt_evtr$mutant)[4]
Col5 <- Col_data
Col5$facet <- unique(melt_evtr$mutant)[5]
Col6 <- Col_data
Col6$facet <- unique(melt_evtr$mutant)[6]
Col7 <- Col_data
Col7$facet <- unique(melt_evtr$mutant)[7]
Col8 <- Col_data
Col8$facet <- unique(melt_evtr$mutant)[8]
Col9 <- Col_data
Col9$facet <- unique(melt_evtr$mutant)[9]
Col10 <- Col_data
Col10$facet <- unique(melt_evtr$mutant)[10]
Col11 <- Col_data
Col11$facet <- unique(melt_evtr$mutant)[11]
Col12 <- Col_data
Col12$facet <- unique(melt_evtr$mutant)[12]
Col13 <- Col_data
Col13$facet <- unique(melt_evtr$mutant)[13]
Col14 <- Col_data
Col14$facet <- unique(melt_evtr$mutant)[14]
Col15 <- Col_data
Col15$facet <- unique(melt_evtr$mutant)[15]

melt_evtr$facet <- melt_evtr$mutant 
EVT_comp <- rbind(melt_evtr, Col1)
EVT_comp <- rbind(EVT_comp, Col2)
EVT_comp <- rbind(EVT_comp, Col3)
EVT_comp <- rbind(EVT_comp, Col4)
EVT_comp <- rbind(EVT_comp, Col5)
EVT_comp <- rbind(EVT_comp, Col6)
EVT_comp <- rbind(EVT_comp, Col7)
EVT_comp <- rbind(EVT_comp, Col8)
EVT_comp <- rbind(EVT_comp, Col9)
EVT_comp <- rbind(EVT_comp, Col10)
EVT_comp <- rbind(EVT_comp, Col11)
EVT_comp <- rbind(EVT_comp, Col12)
EVT_comp <- rbind(EVT_comp, Col13)
EVT_comp <- rbind(EVT_comp, Col14)
EVT_comp <- rbind(EVT_comp, Col15)
unique(EVT_comp$mutant)
##  [1] "Col-0"     "CP.EVT2-1" "CP.EVT2-2" "CP.EVT3-1" "CP.EVT3-2" "CP.EVT6-1"
##  [7] "CP.EVT6-2" "CP.EVT8"   "CP.GR4-1"  "CP.GR4-2"  "CP.NPQ6-1" "CP.NPQ6-2"
## [13] "CP.NPQ6-3" "CP.NPQ6-4" "CP.NPQ6-5"
View(EVT_comp)
EVT_comp$day <- as.numeric(as.character(EVT_comp$day))
EVT_comp <- subset(EVT_comp, EVT_comp$facet != "Col-0")
unique(EVT_comp$facet)
##  [1] "CP.EVT2-1" "CP.EVT2-2" "CP.EVT3-1" "CP.EVT3-2" "CP.EVT6-1" "CP.EVT6-2"
##  [7] "CP.EVT8"   "CP.GR4-1"  "CP.GR4-2"  "CP.NPQ6-1" "CP.NPQ6-2" "CP.NPQ6-3"
## [13] "CP.NPQ6-4" "CP.NPQ6-5"
EVT_G_Col <- ggplot(data = EVT_comp, aes(x = day, y = evapotranspiration, group = plant.id, color = mutant)) + theme_classic()
EVT_G_Col <- EVT_G_Col + geom_line(alpha = 0.1)
EVT_G_Col <- EVT_G_Col + facet_grid(facet ~ treatment)
EVT_G_Col <- EVT_G_Col + stat_summary(fun.data = mean_se, geom = "ribbon", linetype = 0, aes(group = mutant), alpha = 0.3) + stat_summary(fun = mean, aes(group = mutant), size = 0.7, geom = "line", linetype = "solid")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
EVT_G_Col <- EVT_G_Col + stat_compare_means(aes(group = mutant), label = "p.signif", method = "t.test", hide.ns = T, label.y = 5)
EVT_G_Col <- EVT_G_Col + xlab("Day of Stress") + ylab("Evapotranspiration (g)") + rremove("legend")
EVT_G_Col

# pdf("EVT_G_Col_v2.pdf", 7, 9)
# plot(EVT_G_Col)
# dev.off()

#find mean EVT per treatment

evt_c <- subset(melt_evtr, melt_evtr$treatment == "Control")
evt_d <- subset(melt_evtr, melt_evtr$treatment == "Drought")
mean(evt_c$evapotranspiration)
## [1] 14.84888
mean(evt_d$evapotranspiration)
## [1] 8.760045