This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code. This notebook contains code for the EVT, FW, DW, WC analysis of cowpea phenotyping #3.
#Upload necessary libraries and packages
#install.packages(c("ggplot2", "ggpubr", "cowplot", "reshape2"))
library("ggplot2")
library("cowplot")
library("ggpubr")
##
## Attaching package: 'ggpubr'
## The following object is masked from 'package:cowplot':
##
## get_legend
library("reshape2")
#Load data
getwd()
## [1] "C:/Users/J Lab/Box/Plant Architecture Lab/Hayley/Cowpea/Cowpea_screen_03_20220421-0505/Cowpea_Phenotype_exp3_analysis"
list.files(pattern=".csv")
## [1] "EVT_exp3.csv" "FWDWWC_exp3.csv" "Photosynq_exp3.csv"
## [4] "pot_geno_exp3.csv"
evt3exp <- read.csv("EVT_exp3.csv")
head(evt3exp)
#reshape the data to make it workable
melted_3EVT <- melt(evt3exp, id.vars = c("Pot.number", "Genotype", "Treatment"))
colnames(melted_3EVT)[4] <- "Day"
colnames(melted_3EVT)[5] <- "Evapotranspiration"
melted_3EVT$Day <- gsub("Day", "", melted_3EVT$Day)
melted_3EVT$Day <- as.numeric(melted_3EVT$Day)
melted_3EVT$Pot.number <- as.factor(melted_3EVT$Pot.number)
unique(melted_3EVT$Treatment)
## [1] "Control " "Drought" "Control"
melted_3EVT$Treatment <- gsub("Control ", "Control", melted_3EVT$Treatment)
#The lines below were added because the graphs were returning a warning saying that non-finite values were removed under stat_summary and stat_compare_means. The removed values were all NA or negative
melted_3EVTb <- na.omit(melted_3EVT, c("Evapotranspiration"))
melted_3EVTc <- subset(melted_3EVTb, melted_3EVTb$Evapotranspiration >= 0)
melted_3EVTc
#write.csv(melted_3EVTc, "EVT_exp3_melted.csv", row.names = TRUE)
#graph evapotranspiration through time
melted_3EVTc$Pot.number <- as.factor(melted_3EVTc$Pot.number)
EVT3_over_time <- ggplot(data = melted_3EVTc, aes(x = Day, y = Evapotranspiration, group = Pot.number, colour = Treatment), na.rm = TRUE) + theme_classic() + ylim(0, NA)
EVT3_over_time <- EVT3_over_time + geom_line(alpha = 0.1)
EVT3_over_time <- EVT3_over_time + stat_summary(fun.data = mean_se, linetype = 0, aes(group = Treatment), alpha = 0.3) + stat_summary(fun = mean, aes(group = Treatment), size = 0.7, geom = "line", linetype = "dashed")
EVT3_over_time <- EVT3_over_time + facet_wrap(~ Treatment)
EVT3_over_time <- EVT3_over_time + ylab("Evapotranspiration (g)") + xlab("Day") + rremove("legend")
EVT3_over_time
melted_3EVTc$Day <- as.factor(melted_3EVTc$Day)
EVT3_graph_cd <- ggplot(data = melted_3EVTc, aes(x = Day, y = Evapotranspiration, group = Pot.number, colour = Treatment), na.rm = TRUE) + theme_classic() + ylim(0, NA)
EVT3_graph_cd <- EVT3_graph_cd + geom_line(alpha = 0.1)
EVT3_graph_cd <- EVT3_graph_cd + stat_summary(fun.data = mean_se, geom = "ribbon", linetype = 0, aes(group = Treatment), alpha = 0.1) + stat_summary(fun = mean, aes(group = Treatment), size = 0.7, geom = "line", linetype = "dashed")
EVT3_graph_cd <- EVT3_graph_cd + stat_compare_means(aes(group = Treatment), label = "p.signif", method = "t.test", hide.ns = TRUE)
EVT3_graph_cd <- EVT3_graph_cd + scale_color_manual(labels=c("Control", "Drought"), values=c("blue", "red"))
EVT3_graph_cd <- EVT3_graph_cd + ylab("Evapotranspiration (g)") + xlab("Day")
EVT3_graph_cd
#This code is trying to figure out why I'm getting a warning saying removed 4 rows contianing non-finite values for the above EVT graphs. The removed values were all NA or negative, so I added lines of code to remove them in chunk 3
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
ggplotly(EVT3_over_time)
#install.packages("plotly")
#library(plotly)
#ggplotly(EVT3_graph)
list.files(pattern=".csv")
## [1] "EVT_exp3.csv" "FWDWWC_exp3.csv" "Photosynq_exp3.csv"
## [4] "pot_geno_exp3.csv"
FW_DW3 <- read.csv("FWDWWC_exp3.csv")
head(FW_DW3)
#boxplot of fresh weight by Treatment
FW_by_Treatment3 <- ggboxplot(FW_DW3, x="Treatment", y="FW", add="jitter")
FW_by_Treatment3 <- FW_by_Treatment3 + theme(axis.text.x = element_text(angle = 90))
FW_by_Treatment3
#boxplot of dry weight by Treatment
DW_by_Treatment3 <- ggboxplot(FW_DW3, x="Treatment", y="DW", add="jitter")
DW_by_Treatment3 <- DW_by_Treatment3 + theme(axis.text.x = element_text(angle = 90))
DW_by_Treatment3
#boxplot of water content by Treatment
WC_by_Treatment3 <- ggboxplot(FW_DW3, x="Treatment", y="WC", add="jitter")
WC_by_Treatment3 <- WC_by_Treatment3 + theme(axis.text.x = element_text(angle = 90))
WC_by_Treatment3