-
Notifications
You must be signed in to change notification settings - Fork 1
/
Alpha.R
121 lines (99 loc) · 4.2 KB
/
Alpha.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env Rscript
args <- commandArgs(trailingOnly=TRUE)
#main_dir <- dirname(rstudioapi::getSourceEditorContext()$path)
#setwd(main_dir)
library(tidyverse)
library(ggtext)
library(patchwork)
#Alpha
Alpha <- read.csv("Alpha_div/alpha_div_cult.csv")
metadata <- read.csv(args[1])
names(Alpha)[1] <- "sample_id"
names(Alpha)[3] <- "chao1"
names(Alpha)[7] <- "shannon"
names(Alpha)[8] <- "eveness"
Alpha$status <- metadata$HIV_status
chao1_res <- wilcox.test(chao1 ~ status, data = Alpha)
shannon_res <- wilcox.test(shannon ~ status, data = Alpha)
eveness_res <- wilcox.test(eveness ~ status, data = Alpha)
pvals <- c(shannon_res$p.value,
chao1_res$p.value,
eveness_res$p.value)
#####################
###### SHANNON ######
#####################
pvals[1]
shannon <- Alpha %>%
mutate(status=factor(status, levels=c("positive",
"negative"))) %>%
ggplot(aes(x=status, y=shannon, fill = status))+
stat_summary(fun = median, show.legend=FALSE, geom="crossbar")+
geom_jitter(width=0.25, size=2.5, shape=21, color="black")+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black")) +
scale_x_discrete(guide = guide_axis(n.dodge = 2)) +
scale_fill_manual(name = "HIV status",
values=c("#0000FF", "#FF0000")) +
theme(axis.text.x =element_blank(),
axis.ticks.x=element_blank(),
legend.key=element_blank()) +
theme(text = element_text(size = 14)) +
annotate(geom="richtext", x=1.5, y=6,
label= "M-W, <i>p</i>-value<0.001", size=4.5, label.color = NA)+
theme(axis.title.x=element_blank(),
legend.text = element_markdown())+
labs(y= "Shannon index")
####################
###### CHAO1 ######
####################
pvals[2]
chao1 <- Alpha %>%
mutate(status=factor(status, levels=c("positive",
"negative"))) %>%
ggplot(aes(x=status, y=chao1, fill = status))+
stat_summary(fun = median, show.legend=FALSE, geom="crossbar")+
geom_jitter(width=0.25, size=2.5, shape=21, color="black")+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black")) +
scale_x_discrete(guide = guide_axis(n.dodge = 2)) +
scale_fill_manual(name = "HIV status",
values=c("#0000FF", "#FF0000")) +
theme(axis.text.x =element_blank(),
axis.ticks.x=element_blank(),
legend.key=element_blank()) +
theme(text = element_text(size = 14)) +
annotate(geom="richtext", x=1.5, y=650,
label= "M-W, <i>p</i>-value<0.001", size=4.5, label.color = NA)+
theme(axis.title.x=element_blank(),
legend.text = element_markdown())+
labs(y= "Chao1 index")
####################
###### PIELOU ######
####################
pvals[3]
pielou <- Alpha %>%
mutate(status=factor(status, levels=c("positive",
"negative"))) %>%
ggplot(aes(x=status, y=eveness, fill = status))+
stat_summary(fun = median, show.legend=FALSE, geom="crossbar")+
geom_jitter(width=0.25, size=2.5, shape=21, color="black")+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black")) +
scale_x_discrete(guide = guide_axis(n.dodge = 2)) +
scale_fill_manual(name = "HIV status",
values=c("#0000FF", "#FF0000", "grey")) +
theme(axis.text.x =element_blank(),
axis.ticks.x=element_blank(),
legend.key=element_blank()) +
theme(text = element_text(size = 14)) +
annotate(geom="richtext", x=1.5, y=1.5,
label= "M-W, <i>p</i>-value<0.001", size=4.5, label.color = NA)+
theme(axis.title.x=element_blank(),
legend.text = element_markdown())+
labs(y= "Pielou index")
######################
###### COMBINED ######
######################
combined <- (shannon + chao1 + pielou) & theme(legend.position = "bottom")
combined <- combined + plot_layout(guides = "collect") & plot_annotation(tag_levels = list(c("A", "B", "C")))
ggsave(args[2], plot = combined, width = 12, height = 4, dpi=600)