This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
getwd()
## [1] "C:/Users/Julkowska Lab/Desktop/R codes by Maryam/20240820_satistics_DUF247_eLife_revision"
list.files(pattern=".csv")
## [1] "calculateWC-DUF247-5-soil-grown.csv"
## [2] "calculateWC-DUF247-5-soil-grownV2.csv"
## [3] "DUF150-expression-in-col-only.csv"
## [4] "DUF247-expression-in-col-only.csv"
all_data <- read.csv("calculateWC-DUF247-5-soil-grownV2.csv")
all_data
colnames(all_data) <- gsub("ï..", "", colnames(all_data))
all_data
all_data$All.ID<-paste(all_data$Genotype,all_data$Condition,sep="_")
all_data
library(ggplot2)
library(ggpubr)
library(multcompView)
## Warning: package 'multcompView' was built under R version 4.3.2
aov(WC.percentage ~ All.ID, data = all_data)
## Call:
## aov(formula = WC.percentage ~ All.ID, data = all_data)
##
## Terms:
## All.ID Residuals
## Sum of Squares 16.3441 311.1758
## Deg. of Freedom 5 44
##
## Residual standard error: 2.659357
## Estimated effects may be unbalanced
Output <- TukeyHSD(aov(WC.percentage ~ All.ID, data = all_data))
Output
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = WC.percentage ~ All.ID, data = all_data)
##
## $All.ID
## diff lwr upr p adj
## col_EarlyStress-col_ctrl 0.61019925 -3.350812 4.571211 0.9972785
## col_LateStress-col_ctrl -0.16708234 -4.128094 3.793929 0.9999953
## duf_ctrl-col_ctrl 1.16984650 -2.587899 4.927592 0.9372679
## duf_EarlyStress-col_ctrl -0.48483586 -4.445847 3.476175 0.9990965
## duf_LateStress-col_ctrl -0.04071832 -4.001730 3.920293 1.0000000
## col_LateStress-col_EarlyStress -0.77728159 -4.738293 3.183730 0.9915644
## duf_ctrl-col_EarlyStress 0.55964725 -3.198098 4.317392 0.9976824
## duf_EarlyStress-col_EarlyStress -1.09503511 -5.056046 2.865976 0.9615704
## duf_LateStress-col_EarlyStress -0.65091757 -4.611929 3.310094 0.9963064
## duf_ctrl-col_LateStress 1.33692884 -2.420816 5.094674 0.8944080
## duf_EarlyStress-col_LateStress -0.31775352 -4.278765 3.643258 0.9998856
## duf_LateStress-col_LateStress 0.12636402 -3.834647 4.087375 0.9999988
## duf_EarlyStress-duf_ctrl -1.65468235 -5.412428 2.103063 0.7770360
## duf_LateStress-duf_ctrl -1.21056482 -4.968310 2.547180 0.9280756
## duf_LateStress-duf_EarlyStress 0.44411754 -3.516894 4.405129 0.9994097
P7 = Output$All.ID[,'p adj']
stat.test<- multcompLetters(P7)
stat.test
## $Letters
## col_EarlyStress col_LateStress duf_ctrl duf_EarlyStress duf_LateStress
## "a" "a" "a" "a" "a"
## col_ctrl
## "a"
##
## $LetterMatrix
## a
## col_EarlyStress TRUE
## col_LateStress TRUE
## duf_ctrl TRUE
## duf_EarlyStress TRUE
## duf_LateStress TRUE
## col_ctrl TRUE
test <- as.data.frame(stat.test$Letters)
test$group1 <- rownames(test)
test$group2 <- rownames(test)
colnames(test)[1] <- "Tukey"
test
test$info <- strsplit(test$group1, "_")
test$info[[1]][2]
## [1] "EarlyStress"
test$info[[1]][3]
## [1] NA
test$Genotype <- "none"
test$Condition<- "none"
test
for(i in 1:nrow(test)){
test$Genotype[i] <- test$info[[i]][1]
test$Condition[i] <- test$info[[i]][2]
}
test2 <- test[,c(5:6,1)]
test2$group1 <- test2$Genotype
test2$group2 <- test2$Genotype
all_data
all_data$Condition <- factor(all_data$Condition, levels = c("ctrl", "EarlyStress", "LateStress"))
WC_soil_plants <- ggplot(data = all_data, mapping = aes(x = Genotype, y = WC.percentage, colour = Genotype))
WC_soil_plants <- WC_soil_plants + geom_boxplot(alpha=0.2) + geom_jitter(width=0.1,alpha=0.2)
WC_soil_plants <- WC_soil_plants + facet_grid(~Condition, scales = "free_y")
WC_soil_plants <- WC_soil_plants + stat_summary(fun=mean, geom="point", shape=95, size=6, color="black", fill="black")
WC_soil_plants <- WC_soil_plants + scale_color_manual(values = c("blue","red"))
WC_soil_plants <- WC_soil_plants + ylab("Plant Water Content %") + xlab("")+stat_pvalue_manual(test2, label = "Tukey", y.position = 1)
WC_soil_plants <- WC_soil_plants + theme(axis.text.x = element_text(angle=90, hjust=0.9, vjust=0.5))
WC_soil_plants <- WC_soil_plants + rremove("legend")
WC_soil_plants
library(cowplot)
##
## Attaching package: 'cowplot'
## The following object is masked from 'package:ggpubr':
##
## get_legend
pdf("Plants-WC-soil-grown.pdf", height = 5, width = 12)
plot_grid(WC_soil_plants, ncol=2,
align = "hv", labels=c("AUTO"),
label_size = 24)
dev.off()
## png
## 2