-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmg-rast_ko_comparison_2strains.R
114 lines (92 loc) · 3.16 KB
/
mg-rast_ko_comparison_2strains.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
#0# ---------------------------------------------------------------------------------
##
## Name: Pairwise Comparison of 2 Acidovorax strains
## Author: Roberto Siani, MSc
## Date: 200521
## Contact: [email protected]
#1# ---------------------------------------------------------------------------------
#1.1# load libraries
pacman::p_load(tidyverse,
ggpubr,
patchwork,
hrbrthemes)
#1.2# set a general theme for viz
theme_set(theme_ipsum(
plot_margin = margin(0, 0, 1, 1),
base_size = 15,
grid = "XY",
axis_title_size = 15))
#1.3# set a palette
pal = c("#a6bba6",
"#bba6bb")
#2# ---------------------------------------------------------------------------------
#2.1# load exported annotation tsv from MG-RAST
mgrast = read_tsv("~/Desktop/extras/mgrast_ko.tsv",
col_types = "ffffnn") %>%
mutate(level3 = gsub(x = .$level3,
pattern = "\\[[^()]*\\]",
replacement = "")) %>%
mutate(level3 = gsub(x = .$level3,
pattern = "^\\d+",
replacement = ""))
#2.2# convert to relative abundance
perc_mgrast = mgrast %>%
mutate(LjR118 = LjRoot118/sum(LjRoot118)*100,
LjR124 = LjRoot124/sum(LjRoot124)*100) %>%
select(-c(LjRoot118, LjRoot124))
#2.3# convert to long format
long_mgrast = perc_mgrast %>%
pivot_longer(cols = 5:6,
names_to = "Strain",
values_to = "p_tot")
a = ggplot(long_mgrast,
aes(x = level1,
y = p_tot,
fill = Strain)) +
geom_bar(stat = "identity",
position = "dodge") +
coord_flip() +
stat_compare_means(method = "wilcox.test",
paired = T,
label = "p.signif",
hide.ns = T) +
theme(legend.position = "bottom",
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.y = element_text(size = 12)) +
scale_fill_manual(values = pal)
b = ggplot(long_mgrast,
aes(x = level2,
y = p_tot,
fill = Strain)) +
geom_bar(stat = "identity",
position = "dodge") +
coord_flip() +
stat_compare_means(method = "wilcox.test",
paired = T,
label = "p.signif",
hide.ns = T) +
theme(legend.position = "none",
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.y = element_text(size = 10)) +
scale_fill_manual(values = pal)
c = ggplot(long_mgrast,
aes(x = level3,
y = p_tot,
fill = Strain)) +
geom_bar(stat = "identity",
position = "dodge") +
coord_flip() +
stat_compare_means(method = "wilcox.test",
paired = T,
label = "p.signif",
hide.ns = T) +
theme(legend.position = "none",
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.y = element_text(size = 8)) +
scale_fill_manual(values = pal)
a + b + c +
theme(axis.title = element_blank()) +
plot_layout(widths = c(0.8, 1, 1.2))