-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA Computational Metagenomics Project.Rmd
630 lines (523 loc) · 40.1 KB
/
A Computational Metagenomics Project.Rmd
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
---
title: "A Computational Metagenomics Project"
author: "Adrian Lee"
date: "1 May 2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
#Import the required libraries
library(ggplot2)
library(scales)
library(reshape2)
library(ggrepel)
library(RColorBrewer)
library(rprintf)
library(ggpubr)
library(gridExtra)
library(plot3D)
library(plot3Drgl)
library(plotly)
```
First, work with level 3 (class-level) data
```{r, results = 'hide'}
# Read in file
level_3 = read.csv("data/level-3.csv")
classes = as.matrix(level_3[,-c(1,26:30)])
classes
```
Plot correlation heatmap:
```{r}
# Correlations between classes
par(oma = c(13,0,0,13), xpd = TRUE)
heatmap(cor(classes), scale = "none", col = rev(colorRampPalette(brewer.pal(11, "RdBu"))(256)), cexRow = 0.7, cexCol = 0.7, margins = c(7.5,7.5))
legend(x = "bottomright", inset = c(-0.7,-0.55), legend = c(1, 0, -1), fill=colorRampPalette(brewer.pal(11, "RdBu"))(3), cex = 0.5)# , inset = c(0, -2)
```
Visualise the distributions of the relative abundance of each class (level 3)
First, select and transform data into the required format
```{r}
# Relative abundances before and after oil pulling each day
# Select the required data first
before_day_1 = classes[which(level_3[,"Oil.Pulling...Before..2..or.After..1.."] == 2 & level_3[,"Sampling.Day.."] == 1),]
after_day_1 = classes[which(level_3[,"Oil.Pulling...Before..2..or.After..1.."] == 1 & level_3[,"Sampling.Day.."] == 1),]
before_day_16 = classes[which(level_3[,"Oil.Pulling...Before..2..or.After..1.."] == 2 & level_3[,"Sampling.Day.."] == 16),]
after_day_16 = classes[which(level_3[,"Oil.Pulling...Before..2..or.After..1.."] == 1 & level_3[,"Sampling.Day.."] == 16),]
before_day_31 = classes[which(level_3[,"Oil.Pulling...Before..2..or.After..1.."] == 2 & level_3[,"Sampling.Day.."] == 31),]
after_day_31 = classes[which(level_3[,"Oil.Pulling...Before..2..or.After..1.."] == 1 & level_3[,"Sampling.Day.."] == 31),]
# Compute the sums of relative abundances over all samples for each sample collection point
before_day_1_sum = rowSums(before_day_1)
after_day_1_sum = rowSums(after_day_1)
before_day_16_sum = rowSums(before_day_16)
after_day_16_sum = rowSums(after_day_16)
before_day_31_sum = rowSums(before_day_31)
after_day_31_sum = rowSums(after_day_31)
maxlength = max(length(before_day_1_sum), length(after_day_1_sum), length(before_day_16_sum), length(after_day_16_sum), length(before_day_31_sum), length(after_day_31_sum))
# Place sums into a matrix for easier handling
all_abundances_sum_ba_each_day = matrix(data = NA, nrow = maxlength, ncol = 6)
colnames(all_abundances_sum_ba_each_day) = c("Before Day 1", "After Day 1",
"Before Day 16", "After Day 16",
"Before Day 31", "After Day 31")
all_abundances_sum_ba_each_day[,1] = c(before_day_1_sum, rep(NA, maxlength-length(before_day_1_sum)))
all_abundances_sum_ba_each_day[,2] = c(after_day_1_sum, rep(NA, maxlength-length(after_day_1_sum)))
all_abundances_sum_ba_each_day[,3] = c(before_day_16_sum, rep(NA, maxlength-length(before_day_16_sum)))
all_abundances_sum_ba_each_day[,4] = c(after_day_16_sum, rep(NA, maxlength-length(after_day_16_sum)))
all_abundances_sum_ba_each_day[,5] = c(before_day_31_sum, rep(NA, maxlength-length(before_day_31_sum)))
all_abundances_sum_ba_each_day[,6] = c(after_day_31_sum, rep(NA, maxlength-length(after_day_31_sum)))
# Do nothing for missing values
na.pass(all_abundances_sum_ba_each_day)
# Transform (melt) data into a suitable form for subsequent plotting
all_abundances_sum_ba_each_day_melted = melt(all_abundances_sum_ba_each_day)
all_abundances_sum_ba_day_1_melted = melt(all_abundances_sum_ba_each_day[,c(1,2)])
all_abundances_sum_ba_day_16_melted = melt(all_abundances_sum_ba_each_day[,c(3,4)])
all_abundances_sum_ba_day_31_melted = melt(all_abundances_sum_ba_each_day[,c(5,6)])
all_abundances_sum_bb_day1_day_31_melted = melt(all_abundances_sum_ba_each_day[,c(1,5)])
```
Then plot density plots showing relative abundances of CLASSES across all samples between different days
```{r}
plot1 <- ggplot(all_abundances_sum_ba_day_1_melted, aes(x=value, fill=Var2, colour=Var2, rm.na = TRUE)) +
geom_density(alpha=0.25) +
scale_x_continuous(lim = c(0, 115000)) +
scale_y_continuous(lim = c(0, 6*10^-5)) +
labs(x = "Relative abundance", y = "Frequency", title = "Day 1") +
theme(legend.title = element_blank())
plot2 <- ggplot(all_abundances_sum_ba_day_16_melted, aes(x=value, fill=Var2, colour=Var2, rm.na = TRUE)) +
geom_density(alpha=0.25) +
scale_x_continuous(lim = c(0, 115000)) +
scale_y_continuous(lim = c(0, 6*10^-5)) +
labs(x = "Relative abundance", y = "Frequency", title = "Day 16") +
theme(legend.title = element_blank())
plot3 <- ggplot(all_abundances_sum_ba_day_31_melted, aes(x=value, fill=Var2, colour=Var2, rm.na = TRUE)) +
geom_density(alpha=0.25) +
scale_x_continuous(lim = c(0, 115000)) +
scale_y_continuous(lim = c(0, 6*10^-5)) +
labs(x = "Relative abundance", y = "Frequency", title = "Day 31") +
theme(legend.title = element_blank())
plot4 <- ggplot(all_abundances_sum_bb_day1_day_31_melted, aes(x=value, fill=Var2, colour=Var2, rm.na = TRUE)) +
geom_density(alpha=0.25) +
scale_x_continuous(lim = c(0, 115000)) +
scale_y_continuous(lim = c(0, 6*10^-5)) +
labs(x = "Relative abundance", y = "Frequency", title = "Before Day 1 vs. Before Day 31") +
theme(legend.title = element_blank())
# Arrange into a 2x2 format
grid.arrange(plot1, plot2, plot3, plot4, ncol=2)
```
Compare whether there were any statistically significant differences before and after oil pulling on each day, as well as before and after 31 days of oil pulling, using the Mann-Whitney U test
```{r}
#Statistical significance tests
wilcox.test(all_abundances_sum_ba_each_day[,1], all_abundances_sum_ba_each_day[,2], paired = FALSE, alternative = "less")$p.value
wilcox.test(all_abundances_sum_ba_each_day[,3], all_abundances_sum_ba_each_day[,4], paired = FALSE)$p.value
wilcox.test(all_abundances_sum_ba_each_day[,5], all_abundances_sum_ba_each_day[,6], paired = FALSE)$statistic
wilcox.test(all_abundances_sum_ba_each_day[,1], all_abundances_sum_ba_each_day[,5], paired = FALSE)$p.value
```
```{r}
#Relative abundances of CLASSES along time
day_1 = classes[which(level_3[,"Sampling.Day.."] == 1),]
day_16 = classes[which(level_3[,"Sampling.Day.."] == 16),]
day_31 = classes[which(level_3[,"Sampling.Day.."] == 31),]
max_mean_min = matrix(NA, ncol = 24, nrow = 9,
dimnames = list(c("Day 1", "Day 1", "Day 1",
"Day 16", "Day 16", "Day 16",
"Day 31", "Day 31", "Day 31"),
colnames(classes)))
```
Plot line plot showing the relative abundance of classes
The mean, maximum, and minimum relative abundances were first computed.
The maximum and minimum were originally computed for generating error bars, however error bars were not plotted in the end since it would be impractical to plot them when they span the entire y axis. Besides, they would clutter up the plot.
```{r}
max_mean_min[1,] = apply(day_1, 2, max)
max_mean_min[2,] = apply(day_1, 2, mean)
max_mean_min[3,] = apply(day_1, 2, min)
max_mean_min[4,] = apply(day_16, 2, max)
max_mean_min[5,] = apply(day_16, 2, mean)
max_mean_min[6,] = apply(day_16, 2, min)
max_mean_min[7,] = apply(day_31, 2, max)
max_mean_min[8,] = apply(day_31, 2, mean)
max_mean_min[9,] = apply(day_31, 2, min)
write.csv(max_mean_min, "data/max_mean_min.csv")
# Transform (melt) summary statistics into the required form, merge into a matrix for easier handling
max_mean_min_melted = melt(max_mean_min)
max_mean_min_melted = cbind(max_mean_min_melted, rep(c("max", "mean", "min"), nrow(max_mean_min_melted)/3))
colnames(max_mean_min_melted)[4] = "statistic"
max_mean_min_melted[,3] = as.numeric(max_mean_min_melted[,3])
# Plot line plot with ggplot
line_plot = ggplot(max_mean_min_melted, aes(x=Var1, y=value, group=Var2, color=Var2, fill = "")) +
coord_cartesian(clip = "off", expand = TRUE, xlim = c(1,4.25)) +
geom_line(data = subset(max_mean_min_melted, statistic == "mean"), stat = "identity", size = 0.5) +
geom_point(data = subset(max_mean_min_melted, statistic == "mean"), stat = "identity") +
geom_text_repel(data = subset(max_mean_min_melted, statistic == "mean" & Var1 == "Day 31"),
aes(label = Var2, colour = Var2, x = Var1, y = value), size = 4, hjust = -.1, direction = "y", xlim = 4.75, segment.colour = "white") +
labs(title = "Relative abundance of classes", x = "Day", y = "Relative abundance") +
scale_y_log10() +
theme(legend.position = "None",
axis.text = element_text(size = 12),
axis.title = element_text(size = 16),
title = element_text(size = 16))
line_plot
```
Now work with level 6 (genus-level) data
```{r, results = 'hide'}
# Read in file
level_6 = read.csv("data/level-6.csv")
genuses = level_6[,-c(1,72,73,76)]
#The relative abundances of (a subset containing) the most abundant genuses
genuses_subset = level_6[,c(7,9,18,31,43,46,63,70)]
day_1_genuses_subset = genuses_subset[which(level_6[,"Sampling.Day.."] == 1),]
day_16_genuses_subset = genuses_subset[which(level_6[,"Sampling.Day.."] == 16),]
day_31_genuses_subset = genuses_subset[which(level_6[,"Sampling.Day.."] == 31),]
day_1_before_genuses_subset = genuses_subset[which(level_6[,"Sampling.Day.."] == 1 & level_6[,"Oil.Pulling...Before..2..or.After..1.."] == 2),]
day_1_after_genuses_subset = genuses_subset[which(level_6[,"Sampling.Day.."] == 1 & level_6[,"Oil.Pulling...Before..2..or.After..1.."] == 1),]
day_16_before_genuses_subset = genuses_subset[which(level_6[,"Sampling.Day.."] == 16 & level_6[,"Oil.Pulling...Before..2..or.After..1.."] == 2),]
day_16_after_genuses_subset = genuses_subset[which(level_6[,"Sampling.Day.."] == 16 & level_6[,"Oil.Pulling...Before..2..or.After..1.."] == 1),]
day_31_before_genuses_subset = genuses_subset[which(level_6[,"Sampling.Day.."] == 31 & level_6[,"Oil.Pulling...Before..2..or.After..1.."] == 2),]
day_31_after_genuses_subset = genuses_subset[which(level_6[,"Sampling.Day.."] == 31 & level_6[,"Oil.Pulling...Before..2..or.After..1.."] == 1),]
```
Compare whether there were any statistically significant differences before and after oil pulling on each day, as well as before and after 31 days of oil pulling, using the Mann-Whitney U test. Only carried out for the most abundant genera
```{r}
# Insert p-values into a matrix for easier handling
genuses_subset_day_p_values = matrix(data = NA, nrow = ncol(genuses_subset), ncol = 4)
for (genus in 6:ncol(genuses_subset)){
genuses_subset_day_p_values[genus,1] = wilcox.test(day_1_before_genuses_subset[,genus], day_31_before_genuses_subset[,genus], paired = FALSE)$p.value
genuses_subset_day_p_values[genus,2] = wilcox.test(day_1_before_genuses_subset[,genus], day_1_after_genuses_subset[,genus], paired = FALSE)$p.value
genuses_subset_day_p_values[genus,3] = wilcox.test(day_16_before_genuses_subset[,genus], day_16_after_genuses_subset[,genus], paired = FALSE)$p.value
genuses_subset_day_p_values[genus,4] = wilcox.test(day_31_before_genuses_subset[,genus], day_31_after_genuses_subset[,genus], paired = FALSE)$p.value
return(genuses_subset_day_p_values)
}
rownames(genuses_subset_day_p_values) = c("actinomyces", "corynebacterium", "porphyromonas", "streptococcus", "veillonella", "fusobacterium", "haemophilus", "trepenoma")
colnames(genuses_subset_day_p_values) = c("Day 31 Before vs. Day 1 Before",
"Day 1 Before vs. After",
"Day 16 Before vs. After",
"Day 31 Before vs. After")
genuses_subset_day_p_values
```
Explore the use of a balloon plot of relative abundances of top GENUSES for each sample (not used in the end)
```{r}
# Select the required data
genuses_sample_name = rbind(genuses[,-c(71,72)], colSums(genuses))
genuses_sample_name = cbind(genuses_sample_name, c(as.character(level_6[,72]),NA))
genuses_sample_name_ordered_by_sum = genuses_sample_name[,order(as.numeric(genuses_sample_name[55,]), decreasing = FALSE)]
genuses_sample_name_ordered_by_sum_samples = genuses_sample_name_ordered_by_sum[55,]
genuses_sample_name_ordered_by_sum = genuses_sample_name_ordered_by_sum[-55,]
colnames(genuses_sample_name_ordered_by_sum)[71] = "sample_name"
# Transform data into the required form
genuses_sample_name_ordered_by_sum_melted =
melt(genuses_sample_name_ordered_by_sum[,c(ncol(genuses_sample_name_ordered_by_sum)-(10:1),ncol(genuses_sample_name_ordered_by_sum))]) # -> top 10
# Plot the balloon plot
ggballoonplot(genuses_sample_name_ordered_by_sum_melted, x = "sample_name", y = "variable")
```
Using ggplot, plot a heatmap visualise the relative abundances of the 30 most abundant genera at each sample collection point
```{r}
# Select the required data
day_1_before_genuses = genuses[which(level_6[,"Sampling.Day.."] == 1 & level_6[,"Oil.Pulling...Before..2..or.After..1.."] == 2),]
day_1_after_genuses = genuses[which(level_6[,"Sampling.Day.."] == 1 & level_6[,"Oil.Pulling...Before..2..or.After..1.."] == 1),]
day_16_before_genuses = genuses[which(level_6[,"Sampling.Day.."] == 16 & level_6[,"Oil.Pulling...Before..2..or.After..1.."] == 2),]
day_16_after_genuses = genuses[which(level_6[,"Sampling.Day.."] == 16 & level_6[,"Oil.Pulling...Before..2..or.After..1.."] == 1),]
day_31_before_genuses = genuses[which(level_6[,"Sampling.Day.."] == 31 & level_6[,"Oil.Pulling...Before..2..or.After..1.."] == 2),]
day_31_after_genuses = genuses[which(level_6[,"Sampling.Day.."] == 31 & level_6[,"Oil.Pulling...Before..2..or.After..1.."] == 1),]
# Compute the sums over all samples at each sampling point
day_1_before_genuses_sum = colSums(day_1_before_genuses)
day_1_after_genuses_sum = colSums(day_1_after_genuses)
day_16_before_genuses_sum = colSums(day_16_before_genuses)
day_16_after_genuses_sum = colSums(day_16_after_genuses)
day_31_before_genuses_sum = colSums(day_31_before_genuses)
day_31_after_genuses_sum = colSums(day_31_after_genuses)
# Insert sums into matrix for easier handling
all_days_genuses_sum = rbind(day_1_before_genuses_sum, day_1_after_genuses_sum, day_16_before_genuses_sum,
day_16_after_genuses_sum, day_31_before_genuses_sum, day_31_after_genuses_sum)[,-c(71,72)]
# Sort columns (i.e. genera) according to the total relative abundance, so that the most abundant ones are on the top of the plot
all_days_genuses_sum = all_days_genuses_sum[,order(colSums(all_days_genuses_sum), decreasing = FALSE)]
# Transform (melt) data into the required form
all_days_genuses_sum_melted = melt(all_days_genuses_sum[,c(ncol(all_days_genuses_sum)-(29:0))])
all_days_genuses_sum_melted[,"value"] = sqrt(all_days_genuses_sum_melted[,"value"])
# Plot the heatmap
genera_heatmap = ggplot(all_days_genuses_sum_melted, mapping = aes(x = Var1, y = Var2, fill = value)) +
geom_tile() +
scale_fill_gradientn(colours = c("Blue", "White", "Red"), values = c(0,0.5,1), limits = c(0,400)) +
scale_x_discrete("Day", labels = c("Day 1 Before", "Day 1 After", "Day 16 Before", "Day 16 After", "Day 31 Before", "Day 31 After")) +
ylab("Genera") +
labs(fill = "Square root of relative abundance")
genera_heatmap
```
Now analyse beta diversity
```{r}
# Read in files for each beta diversity metric
bray_curtis = read.table("diversity_metrics/beta/bray_curtis-distance_matrix.tsv")
generalized_unifrac = read.table("diversity_metrics/beta/generalized_unifrac-distance_matrix.tsv")
jaccard = read.table("diversity_metrics/beta/jaccard-distance_matrix.tsv")
unweighted_unifrac = read.table("diversity_metrics/beta/unweighted_unifrac-distance_matrix.tsv")
weighted_normalized_unifrac = read.table("diversity_metrics/beta/weighted_normalized_unifrac-distance_matrix.tsv")
weighted_unifrac = read.table("diversity_metrics/beta/weighted_unifrac-distance_matrix.tsv")
# Select samples for each day and before and after oil pulling
sampling.day.1 = c("515rcbc257", "515rcbc263", "515rcbc479", "515rcbc454", "515rcbc239", "515rcbc254", "515rcbc251", "515rcbc245", "515rcbc269",
"515rcbc242", "515rcbc467", "515rcbc461", "515rcbc482", "515rcbc266", "515rcbc248", "515rcbc458")
sampling.day.16 = c("515rcbc255", "515rcbc267", "515rcbc264", "515rcbc495", "515rcbc243", "515rcbc464", "515rcbc240", "515rcbc249", "515rcbc470",
"515rcbc261", "515rcbc252", "515rcbc480", "515rcbc456", "515rcbc462", "515rcbc270", "515rcbc258", "515rcbc483")
sampling.day.31 = c("515rcbc247", "515rcbc496", "515rcbc484", "515rcbc271", "515rcbc472", "515rcbc259", "515rcbc265", "515rcbc256", "515rcbc466",
"515rcbc457", "515rcbc471", "515rcbc262", "515rcbc478", "515rcbc465", "515rcbc253", "515rcbc268", "515rcbc493", "515rcbc241",
"515rcbc250", "515rcbc244", "515rcbc477")
before.oil.pulling = c("515rcbc454", "515rcbc254", "515rcbc242", "515rcbc467", "515rcbc482", "515rcbc266", "515rcbc248", "515rcbc458", "515rcbc255",
"515rcbc267", "515rcbc495", "515rcbc243", "515rcbc249", "515rcbc261", "515rcbc456", "515rcbc462", "515rcbc483", "515rcbc496",
"515rcbc484", "515rcbc256", "515rcbc457", "515rcbc471", "515rcbc262", "515rcbc465", "515rcbc268", "515rcbc250", "515rcbc244",
"515rcbc477")
after.oil.pulling = c("515rcbc257", "515rcbc263", "515rcbc479", "515rcbc239", "515rcbc251", "515rcbc245", "515rcbc269", "515rcbc461", "515rcbc264",
"515rcbc464", "515rcbc240", "515rcbc470", "515rcbc252", "515rcbc480", "515rcbc270", "515rcbc258", "515rcbc247", "515rcbc271",
"515rcbc472", "515rcbc259", "515rcbc265", "515rcbc466", "515rcbc478", "515rcbc253", "515rcbc493", "515rcbc241")
```
Principle coordinate analysis (PCoA) for dimensionality reduction and for finding out the percentage variance explained by the top three components
```{r}
# Compute principle components
pc.bray_curtis = prcomp(bray_curtis)
pc.generalized_unifrac = prcomp(generalized_unifrac)
pc.jaccard = prcomp(jaccard)
pc.unweighted_unifrac = prcomp(unweighted_unifrac)
pc.weighted_normalized_unifrac = prcomp(weighted_normalized_unifrac)
pc.weighted_unifrac = prcomp(weighted_unifrac)
# Find out percentage variance explained
pc.bray_curtis$sdev[1:3]^2/sum(pc.bray_curtis$sdev^2)
pc.generalized_unifrac$sdev[1:3]^2/sum(pc.generalized_unifrac$sdev^2)
pc.jaccard$sdev[1:3]^2/sum(pc.jaccard$sdev^2)
pc.unweighted_unifrac$sdev[1:3]^2/sum(pc.unweighted_unifrac$sdev^2)
pc.weighted_normalized_unifrac$sdev[1:3]^2/sum(pc.weighted_normalized_unifrac$sdev^2)
pc.weighted_unifrac$sdev[1:3]^2/sum(pc.weighted_unifrac$sdev^2)
# Create barplot to visualise percentage variance explained for the all metrics
bar.plot = t(data.frame("Bray Curtis" = sum(pc.bray_curtis$sdev[1:3]^2/sum(pc.bray_curtis$sdev^2)),
"Generalized UniFrac" = sum(pc.generalized_unifrac$sdev[1:3]^2/sum(pc.generalized_unifrac$sdev^2)),
"Jaccard" = sum(pc.jaccard$sdev[1:3]^2/sum(pc.jaccard$sdev^2)),
"Unweighted UniFrac" = sum(pc.unweighted_unifrac$sdev[1:3]^2/sum(pc.unweighted_unifrac$sdev^2)),
"Weighted Normalized UniFrac" = sum(pc.weighted_normalized_unifrac$sdev[1:3]^2/sum(pc.weighted_normalized_unifrac$sdev^2)),
"Weighted UniFrac" = sum(pc.weighted_unifrac$sdev[1:3]^2/sum(pc.weighted_unifrac$sdev^2))))
# Only the three representative metrics (Bray Curtis, Jaccard, and unweighted UniFrac) were plotted
barplot(bar.plot[c(1,3,4),1], ylim = c(0,1), ylab = "Percentage variance explained", col = "black") +
grid(NA, 5, lty = 1, col = "grey", lwd = 0.5)
print(sprintf("The percentage variance explained is %3f", pc.bray_curtis$sdev[1:3]^2/sum(pc.bray_curtis$sdev^2)))
```
Plot 3D scatter plots of PCoA results
The section immediately below transforms results into the required format (a tedious process...)
```{r}
pc.bray_curtis.grouped = data.frame(cbind(pc.bray_curtis$x[,1:3], ba = rep(NA, nrow(pc.bray_curtis$x)), group = rep(NA, nrow(pc.bray_curtis$x)), colour = rep(NA, nrow(pc.bray_curtis$x))))
pc.generalized_unifrac.grouped = data.frame(cbind(pc.generalized_unifrac$x[,1:3], ba = rep(NA, nrow(pc.generalized_unifrac$x)), group = rep(NA, nrow(pc.generalized_unifrac$x)), colour = rep(NA, nrow(pc.generalized_unifrac$x))))
pc.jaccard.grouped = data.frame(cbind(pc.jaccard$x[,1:3], ba = rep(NA, nrow(pc.jaccard$x)), group = rep(NA, nrow(pc.jaccard$x)), colour = rep(NA, nrow(pc.jaccard$x))))
pc.unweighted_unifrac.grouped = data.frame(cbind(pc.unweighted_unifrac$x[,1:3], ba = rep(NA, nrow(pc.unweighted_unifrac$x)), group = rep(NA, nrow(pc.unweighted_unifrac$x)), colour = rep(NA, nrow(pc.unweighted_unifrac$x))))
pc.weighted_normalized_unifrac.grouped = data.frame(cbind(pc.weighted_normalized_unifrac$x[,1:3], ba = rep(NA, nrow(pc.weighted_normalized_unifrac$x)), group = rep(NA, nrow(pc.weighted_normalized_unifrac$x)), colour = rep(NA, nrow(pc.weighted_normalized_unifrac$x))))
pc.weighted_unifrac.grouped = data.frame(cbind(pc.weighted_unifrac$x[,1:3], ba = rep(NA, nrow(pc.weighted_unifrac$x)), group = rep(NA, nrow(pc.weighted_unifrac$x)), colour = rep(NA, nrow(pc.weighted_unifrac$x))))
scatter.grouped = function(grouped){
grouped[intersect(sampling.day.1, before.oil.pulling),"group"] = "Before Day 1"
grouped[intersect(sampling.day.1, after.oil.pulling),"group"] = "After Day 1"
grouped[intersect(sampling.day.16, before.oil.pulling),"group"] = "Before Day 16"
grouped[intersect(sampling.day.16, after.oil.pulling),"group"] = "After Day 16"
grouped[intersect(sampling.day.31, before.oil.pulling),"group"] = "Before Day 31"
grouped[intersect(sampling.day.31, after.oil.pulling),"group"] = "After Day 31"
grouped[intersect(sampling.day.1, before.oil.pulling),"colour"] = "#F8766D"
grouped[intersect(sampling.day.1, after.oil.pulling),"colour"] = "#F6F86D"
grouped[intersect(sampling.day.16, before.oil.pulling),"colour"] = "#00BA38"
grouped[intersect(sampling.day.16, after.oil.pulling),"colour"] = "#00BCD8"
grouped[intersect(sampling.day.31, before.oil.pulling),"colour"] = "#000000"
grouped[intersect(sampling.day.31, after.oil.pulling),"colour"] = "#E76BF3"
grouped[before.oil.pulling,"ba"] = "Before"
grouped[after.oil.pulling,"ba"] = "After"
return(grouped)
}
pc.bray_curtis.grouped = scatter.grouped(pc.bray_curtis.grouped)
pc.generalized_unifrac.grouped = scatter.grouped(pc.generalized_unifrac.grouped)
pc.jaccard.grouped = scatter.grouped(pc.jaccard.grouped)
pc.unweighted_unifrac.grouped = scatter.grouped(pc.unweighted_unifrac.grouped)
pc.weighted_normalized_unifrac.grouped = scatter.grouped(pc.weighted_normalized_unifrac.grouped)
pc.weighted_unifrac.grouped = scatter.grouped(pc.weighted_unifrac.grouped)
pc.bray_curtis.grouped.1.31 = pc.bray_curtis.grouped[intersect(c(sampling.day.1,sampling.day.31), before.oil.pulling),]
pc.jaccard.grouped.1.31 = pc.jaccard.grouped[intersect(c(sampling.day.1,sampling.day.31), before.oil.pulling),]
pc.unweighted_unifrac.grouped.1.31 = pc.unweighted_unifrac.grouped[intersect(c(sampling.day.1,sampling.day.31), before.oil.pulling),]
```
Finally, plot the 3D scatter plots (plots may not show up properly since RMarkdown does not always produce the same results as RStudio)
```{r, warning=FALSE}
par(mfrow=c(3,2), mar=c(1,0,1,0))
bray_curtis.scatter = scatter3D(pc.bray_curtis.grouped[,1], pc.bray_curtis.grouped[,2], pc.bray_curtis.grouped[,3],
xlab = sprintf("\nPrincipal Component 1 \n(%.3f%%)", pc.bray_curtis$sdev[1:3]^2/sum(pc.bray_curtis$sdev^2)*100)[1],
ylab = sprintf("\nPrincipal Component 2 \n(%.3f%%)", pc.bray_curtis$sdev[1:3]^2/sum(pc.bray_curtis$sdev^2)*100)[2],
zlab = sprintf("\nPrincipal Component 3 \n(%.3f%%)", pc.bray_curtis$sdev[1:3]^2/sum(pc.bray_curtis$sdev^2)*100)[3],
col = pc.bray_curtis.grouped[,6], type = "p", angle = 45, box = TRUE, colvar = NULL,
theta = 20, phi = 20, main = "PCoA of Bray Curtis Distances", cex.main = 1.3,
alpha = 0.5, pch = 16, cex = 2)
jaccard.scatter = scatter3D(pc.jaccard.grouped[,1], pc.jaccard.grouped[,2], pc.jaccard.grouped[,3],
xlab = sprintf("\nPrincipal Component 1 \n(%.3f%%)", pc.jaccard$sdev[1:3]^2/sum(pc.jaccard$sdev^2)*100)[1],
ylab = sprintf("\nPrincipal Component 2 \n(%.3f%%)", pc.jaccard$sdev[1:3]^2/sum(pc.jaccard$sdev^2)*100)[2],
zlab = sprintf("\nPrincipal Component 3 \n(%.3f%%)", pc.jaccard$sdev[1:3]^2/sum(pc.jaccard$sdev^2)*100)[3],
col = pc.jaccard.grouped[,6], type = "p", angle = 45, box = TRUE, colvar = NULL,
theta = 20, phi = 20, main = "PCoA of Jaccard Distances", cex.main = 1.3,
alpha = 0.5, pch = 16, cex = 2)
unweighted_unifrac.scatter = scatter3D(pc.unweighted_unifrac.grouped[,1], pc.unweighted_unifrac.grouped[,2], pc.unweighted_unifrac.grouped[,3],
xlab = sprintf("\nPrincipal Component 1 \n(%.3f%%)", pc.unweighted_unifrac$sdev[1:3]^2/sum(pc.unweighted_unifrac$sdev^2)*100)[1],
ylab = sprintf("\nPrincipal Component 2 \n(%.3f%%)", pc.unweighted_unifrac$sdev[1:3]^2/sum(pc.unweighted_unifrac$sdev^2)*100)[2],
zlab = sprintf("\nPrincipal Component 3 \n(%.3f%%)", pc.unweighted_unifrac$sdev[1:3]^2/sum(pc.unweighted_unifrac$sdev^2)*100)[3],
col = pc.unweighted_unifrac.grouped[,6], type = "p", angle = 45, box = TRUE, colvar = NULL,
theta = 20, phi = 20, main = "PCoA of Unweighted UniFrac Distances", cex.main = 1.3,
alpha = 0.5, pch = 16, cex = 2)
bray_curtis.scatter.1.31 = scatter3D(pc.bray_curtis.grouped.1.31[,1], pc.bray_curtis.grouped.1.31[,2], pc.bray_curtis.grouped.1.31[,3],
xlab = sprintf("\nPrincipal Component 1 \n(%.3f%%)", pc.bray_curtis$sdev[1:3]^2/sum(pc.bray_curtis$sdev^2)*100)[1],
ylab = sprintf("\nPrincipal Component 2 \n(%.3f%%)", pc.bray_curtis$sdev[1:3]^2/sum(pc.bray_curtis$sdev^2)*100)[2],
zlab = sprintf("\nPrincipal Component 3 \n(%.3f%%)", pc.bray_curtis$sdev[1:3]^2/sum(pc.bray_curtis$sdev^2)*100)[3],
col = pc.bray_curtis.grouped.1.31[,6], type = "p", angle = 45, box = TRUE, colvar = NULL,
theta = 20, phi = 20, cex.main = 1.3,
alpha = 0.5, pch = 16, cex = 2)
jaccard.scatter.1.31 = scatter3D(pc.jaccard.grouped.1.31[,1], pc.jaccard.grouped.1.31[,2], pc.jaccard.grouped.1.31[,3],
xlab = sprintf("\nPrincipal Component 1 \n(%.3f%%)", pc.jaccard$sdev[1:3]^2/sum(pc.jaccard$sdev^2)*100)[1],
ylab = sprintf("\nPrincipal Component 2 \n(%.3f%%)", pc.jaccard$sdev[1:3]^2/sum(pc.jaccard$sdev^2)*100)[2],
zlab = sprintf("\nPrincipal Component 3 \n(%.3f%%)", pc.jaccard$sdev[1:3]^2/sum(pc.jaccard$sdev^2)*100)[3],
col = pc.jaccard.grouped.1.31[,6], type = "p", angle = 45, box = TRUE, colvar = NULL,
theta = 20, phi = 20, cex.main = 1.3,
alpha = 0.5, pch = 16, cex = 2)
unweighted_unifrac.scatter.1.31 = scatter3D(pc.unweighted_unifrac.grouped.1.31[,1], pc.unweighted_unifrac.grouped.1.31[,2], pc.unweighted_unifrac.grouped.1.31[,3],
xlab = sprintf("\nPrincipal Component 1 \n(%.3f%%)", pc.unweighted_unifrac$sdev[1:3]^2/sum(pc.unweighted_unifrac$sdev^2)*100)[1],
ylab = sprintf("\nPrincipal Component 2 \n(%.3f%%)", pc.unweighted_unifrac$sdev[1:3]^2/sum(pc.unweighted_unifrac$sdev^2)*100)[2],
zlab = sprintf("\nPrincipal Component 3 \n(%.3f%%)", pc.unweighted_unifrac$sdev[1:3]^2/sum(pc.unweighted_unifrac$sdev^2)*100)[3],
col = pc.unweighted_unifrac.grouped.1.31[,6], type = "p", angle = 45, box = TRUE, colvar = NULL,
theta = 20, phi = 20, cex.main = 1.3,
alpha = 0.5, pch = 16, cex = 2)
generalized_unifrac.scatter = scatter3D(pc.generalized_unifrac.grouped[,1], pc.generalized_unifrac.grouped[,2], pc.generalized_unifrac.grouped[,3],
xlab = sprintf("\nPrincipal Component 1 \n(%.3f%%)", pc.generalized_unifrac$sdev[1:3]^2/sum(pc.generalized_unifrac$sdev^2)*100)[1],
ylab = sprintf("\nPrincipal Component 2 \n(%.3f%%)", pc.generalized_unifrac$sdev[1:3]^2/sum(pc.generalized_unifrac$sdev^2)*100)[2],
zlab = sprintf("\nPrincipal Component 3 \n(%.3f%%)", pc.generalized_unifrac$sdev[1:3]^2/sum(pc.generalized_unifrac$sdev^2)*100)[3],
col = pc.jaccard.grouped[,6], type = "p", angle = 45, box = TRUE, colvar = NULL,
theta = 20, phi = 20, main = "PCA of Generalized UniFrac Distances", cex.main = 1.3,
alpha = 0.5, pch = 16, cex = 2)
weighted_normalized_unifrac.scatter = scatter3D(pc.weighted_normalized_unifrac.grouped[,1], pc.weighted_normalized_unifrac.grouped[,2], pc.weighted_normalized_unifrac.grouped[,3],
xlab = sprintf("\nPrincipal Component 1 \n(%.3f%%)", pc.weighted_normalized_unifrac$sdev[1:3]^2/sum(pc.weighted_normalized_unifrac$sdev^2)*100)[1],
ylab = sprintf("\nPrincipal Component 2 \n(%.3f%%)", pc.weighted_normalized_unifrac$sdev[1:3]^2/sum(pc.weighted_normalized_unifrac$sdev^2)*100)[2],
zlab = sprintf("\nPrincipal Component 3 \n(%.3f%%)", pc.weighted_normalized_unifrac$sdev[1:3]^2/sum(pc.weighted_normalized_unifrac$sdev^2)*100)[3],
col = pc.weighted_normalized_unifrac.grouped[,6], type = "p", angle = 45, box = TRUE, colvar = NULL,
theta = 20, phi = 20, main = "PCA of Weighted Normalized UniFrac Distances", cex.main = 1.3,
alpha = 0.5, pch = 16, cex = 2)
weighted_unifrac.scatter = scatter3D(pc.weighted_unifrac.grouped[,1], pc.weighted_unifrac.grouped[,2], pc.weighted_unifrac.grouped[,3],
xlab = sprintf("\nPrincipal Component 1 \n(%.3f%%)", pc.weighted_unifrac$sdev[1:3]^2/sum(pc.weighted_unifrac$sdev^2)*100)[1],
ylab = sprintf("\nPrincipal Component 2 \n(%.3f%%)", pc.weighted_unifrac$sdev[1:3]^2/sum(pc.weighted_unifrac$sdev^2)*100)[2],
zlab = sprintf("\nPrincipal Component 3 \n(%.3f%%)", pc.weighted_unifrac$sdev[1:3]^2/sum(pc.weighted_unifrac$sdev^2)*100)[3],
col = pc.weighted_unifrac.grouped[,6], type = "p", angle = 45, box = TRUE, colvar = NULL,
theta = 20, phi = 20, main = "PCA of Weighted UniFrac Distances", cex.main = 1.3,
alpha = 0.5, pch = 16, cex = 2)
plot(pc.weighted_unifrac.grouped[,1], pc.weighted_unifrac.grouped[,2],
xlab = sprintf("\nPrincipal Component 1 \n(%.3f%%)", pc.weighted_unifrac$sdev[1:3]^2/sum(pc.weighted_unifrac$sdev^2)*100)[1],
ylab = sprintf("\nPrincipal Component 1 \n(%.3f%%)", pc.weighted_unifrac$sdev[1:3]^2/sum(pc.weighted_unifrac$sdev^2)*100)[2],
col = pc.weighted_unifrac.grouped[,6], type = "p", angle = 45, box = TRUE, colvar = NULL,
theta = 20, phi = 20, main = "PCA of Weighted UniFrac Distances", cex.main = 1.3,
alpha = 0.5, pch = 16, cex = 2, legend = TRUE)
dev.off()
```
Plot box plots to visualise the distributions of beta diversity metrics
Again, the section immediately below transforms results into the required format
```{r}
bray_curtis.grouped = cbind(bray_curtis, ba = rep(NA, nrow(pc.bray_curtis$x)),group = rep(NA, nrow(bray_curtis)), day = rep(NA, nrow(bray_curtis)))
generalized_unifrac.grouped = cbind(generalized_unifrac, ba = rep(NA, nrow(pc.generalized_unifrac$x)), group = rep(NA, nrow(generalized_unifrac)), day = rep(NA, nrow(generalized_unifrac)))
jaccard.grouped = cbind(jaccard, ba = rep(NA, nrow(pc.jaccard$x)), group = rep(NA, nrow(jaccard)), day = rep(NA, nrow(jaccard)))
unweighted_unifrac.grouped = cbind(unweighted_unifrac, ba = rep(NA, nrow(pc.unweighted_unifrac$x)), group = rep(NA, nrow(unweighted_unifrac)), day = rep(NA, nrow(unweighted_unifrac)))
weighted_normalized_unifrac.grouped = cbind(weighted_normalized_unifrac, ba = rep(NA, nrow(pc.unweighted_unifrac$x)), group = rep(NA, nrow(weighted_normalized_unifrac)), day = rep(NA, nrow(weighted_normalized_unifrac)))
weighted_unifrac.grouped = cbind(weighted_unifrac, ba = rep(NA, nrow(pc.weighted_unifrac$x)), group = rep(NA, nrow(weighted_unifrac)), day = rep(NA, nrow(weighted_unifrac)))
box.grouped = function(grouped){
grouped[intersect(sampling.day.1, before.oil.pulling),"group"] = "Before Day 1"
grouped[intersect(sampling.day.1, after.oil.pulling),"group"] = "After Day 1"
grouped[intersect(sampling.day.16, before.oil.pulling),"group"] = "Before Day 16"
grouped[intersect(sampling.day.16, after.oil.pulling),"group"] = "After Day 16"
grouped[intersect(sampling.day.31, before.oil.pulling),"group"] = "Before Day 31"
grouped[intersect(sampling.day.31, after.oil.pulling),"group"] = "After Day 31"
grouped[sampling.day.1,"day"] = "Day 1"
grouped[sampling.day.16,"day"] = "Day 16"
grouped[sampling.day.31,"day"] = "Day 31"
grouped[before.oil.pulling,"ba"] = "Before"
grouped[after.oil.pulling,"ba"] = "After"
grouped$group = factor(grouped$group, levels = c("Before Day 1","After Day 1","Before Day 16","After Day 16","Before Day 31","After Day 31"))
return(grouped)
}
bray_curtis.grouped = box.grouped(bray_curtis.grouped)
generalized_unifrac.grouped = box.grouped(generalized_unifrac.grouped)
jaccard.grouped = box.grouped(jaccard.grouped)
unweighted_unifrac.grouped = box.grouped(unweighted_unifrac.grouped)
weighted_normalized_unifrac.grouped = box.grouped(weighted_normalized_unifrac.grouped)
weighted_unifrac.grouped = box.grouped(weighted_unifrac.grouped)
bray_curtis.grouped.melted = melt(bray_curtis.grouped)
generalized_unifrac.grouped.melted = melt(generalized_unifrac.grouped)
jaccard.grouped.melted = melt(jaccard.grouped)
unweighted_unifrac.grouped.melted = melt(unweighted_unifrac.grouped)
weighted_normalized_unifrac.grouped.melted = melt(weighted_normalized_unifrac.grouped)
weighted_unifrac.grouped.melted = melt(weighted_unifrac.grouped)
```
Plot the boxplots
```{r}
bray_curtis.box = ggplot(bray_curtis.grouped.melted, aes(x = factor(group, levels = levels(factor(group))), y = value, color = group)) +
geom_boxplot() +
labs(title = "Bray Curtis", x = "", y = "Distance") +
facet_wrap(~ day, scales = "free_x") +
scale_x_discrete(labels = c("Before", "After")) +
scale_y_continuous(limits = c(0,1)) +
theme(legend.position = "none")
scale_color_manual(name = "group",
breaks = c("Before Day 1","After Day 1","Before Day 16","After Day 16","Before Day 31","After Day 31"),
values = c("#F8766D", "#F6F86D", "#00BA38", "#00BCD8", "#000000", "#E76BF3"))
generalized_unifrac.box = ggplot(generalized_unifrac.grouped.melted, aes(x = factor(group, levels = levels(factor(group))), y = value, color = group)) +
geom_boxplot() +
labs(title = "Generalized UniFrac", x = "", y = "Distance") +
facet_wrap(~ day, scales = "free_x") +
scale_x_discrete(labels = c("Before", "After")) +
scale_y_continuous(limits = c(0,1)) +
theme(legend.position = "none")
scale_color_manual(name = "group",
breaks = c("Before Day 1","After Day 1","Before Day 16","After Day 16","Before Day 31","After Day 31"),
values = c("#F8766D", "#F6F86D", "#00BA38", "#00BCD8", "#000000", "#E76BF3"))
jaccard.box = ggplot(jaccard.grouped.melted, aes(x = factor(group, levels = levels(factor(group))), y = value, color = group)) +
geom_boxplot() +
labs(title = "Jaccard", x = "", y = "Distance") +
facet_wrap(~ day, scales = "free_x") +
scale_x_discrete(labels = c("Before", "After")) +
scale_y_continuous(limits = c(0,1)) +
theme(legend.position = "none")
scale_color_manual(name = "group",
breaks = c("Before Day 1","After Day 1","Before Day 16","After Day 16","Before Day 31","After Day 31"),
values = c("#F8766D", "#F6F86D", "#00BA38", "#00BCD8", "#000000", "#E76BF3"))
unweighted_unifrac.box = ggplot(unweighted_unifrac.grouped.melted, aes(x = factor(group, levels = levels(factor(group))), y = value, color = group)) +
geom_boxplot() +
labs(title = "Unweighted UniFrac", x = "", y = "Distance") +
facet_wrap(~ day, scales = "free_x") +
scale_x_discrete(labels = c("Before", "After")) +
scale_y_continuous(limits = c(0,1)) +
theme(legend.position = "none") +
scale_color_manual(name = "group",
breaks = c("Before Day 1","After Day 1","Before Day 16","After Day 16","Before Day 31","After Day 31"),
values = c("#F8766D", "#F6F86D", "#00BA38", "#00BCD8", "#000000", "#E76BF3"))
weighted_normalized_unifrac.box = ggplot(weighted_normalized_unifrac.grouped.melted, aes(x = factor(group, levels = levels(factor(group))), y = value, color = group)) +
geom_boxplot() +
labs(title = "Weighted Normalized UniFrac", x = "", y = "Distance") +
facet_wrap(~ day, scales = "free_x") +
scale_x_discrete(labels = c("Before", "After")) +
scale_y_continuous(limits = c(0,1)) +
theme(legend.position = "none", axis.title.y = element_blank())
scale_color_manual(name = "group",
breaks = c("Before Day 1","After Day 1","Before Day 16","After Day 16","Before Day 31","After Day 31"),
values = c("#F8766D", "#F6F86D", "#00BA38", "#00BCD8", "#000000", "#E76BF3"))
weighted_unifrac.box = ggplot(weighted_unifrac.grouped.melted, aes(x = factor(group, levels = levels(factor(group))), y = value, color = group)) +
geom_boxplot() +
labs(title = "Weighted UniFrac", x = "", y = "Distance") +
facet_wrap(~ day, scales = "free_x") +
scale_x_discrete(labels = c("Before", "After")) +
scale_y_continuous(limits = c(0,1)) +
theme(legend.position = "none", axis.title.y = element_blank())
scale_color_manual(name = "group",
breaks = c("Before Day 1","After Day 1","Before Day 16","After Day 16","Before Day 31","After Day 31"),
values = c("#F8766D", "#F6F86D", "#00BA38", "#00BCD8", "#000000", "#E76BF3"))
grid.arrange(bray_curtis.box,jaccard.box,
unweighted_unifrac.box,
ncol = 2)
```
Statistical tests for testing whether the distributions of each beta diversity metric were significantly different between different sampling points
```{r}
#Mann-Whitney U tests for all beta metrics
compare_means(value ~ day, bray_curtis.grouped.melted, method = "wilcox.test", group.by = "ba")
compare_means(value ~ day, generalized_unifrac.grouped.melted, method = "wilcox.test", group.by = "ba")
compare_means(value ~ day, jaccard.grouped.melted, method = "wilcox.test", group.by = "ba")
compare_means(value ~ day, unweighted_unifrac.grouped.melted, method = "wilcox.test", group.by = "ba")
compare_means(value ~ day, weighted_normalized_unifrac.grouped.melted, method = "wilcox.test", group.by = "ba")
compare_means(value ~ day, weighted_unifrac.grouped.melted, method = "wilcox.test", group.by = "ba")
compare_means(value ~ group, bray_curtis.grouped.melted, method = "wilcox.test", group.by = "day")
compare_means(value ~ group, generalized_unifrac.grouped.melted, method = "wilcox.test", group.by = "day")
compare_means(value ~ group, jaccard.grouped.melted, method = "wilcox.test", group.by = "day")
compare_means(value ~ group, unweighted_unifrac.grouped.melted, method = "wilcox.test", group.by = "day")
compare_means(value ~ group, weighted_normalized_unifrac.grouped.melted, method = "wilcox.test", group.by = "day")
compare_means(value ~ group, weighted_unifrac.grouped.melted, method = "wilcox.test", group.by = "day")
```