-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathvideo_code.Rmd
100 lines (79 loc) · 2.05 KB
/
video_code.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
---
title: "SCIP barplot"
output: html_notebook
---
```{r}
library(tidyverse)
```
```{r}
Tab <- read_tsv("data/rhizo/otu_table.tsv",
col_types = cols(otu_id = col_character(),
.default = col_number()))
Tab
```
```{r}
dat <- Tab %>%
pivot_longer(-otu_id, names_to = "sample_id", values_to = "count")
dat
```
```{r}
Tax <- read_tsv("data/rhizo/otu_taxonomy.tsv",
col_types = cols(.default = "character"))
Tax
```
```{r}
dat <- dat %>%
left_join(Tax, by = "otu_id")
dat
```
```{r}
Meta <- read_tsv("data/rhizo/sample_metadata.tsv",
col_types = cols(.default = col_character()))
Meta
```
```{r}
dat <- dat %>%
left_join(Meta, by = "sample_id")
dat
```
```{r}
dat %>%
ggplot(aes(x = sample_id, y = count)) +
facet_grid(~ fraction + soil, scales = "free_x", space = "free_x") +
geom_bar(aes(fill = Phylum), stat = "identity", position = "fill", width = 1)
```
```{r}
dat %>%
ggplot(aes(x = sample_id, y = count)) +
facet_grid(~ fraction + soil, scales = "free_x", space = "free_x") +
geom_bar(aes(fill = Phylum), stat = "identity", position = "fill", width = 1) +
scale_fill_brewer(palette = "Paired")
```
```{r}
phyla_order <- c("Proteobacteria",
"Actinobacteria",
"Bacteroidetes",
"Acidobacteria",
"Firmicutes",
"Cyanobacteria",
"Verrucomicrobia",
"Gemmatimonadetes",
"Armatimonadetes",
"Chloroflexi",
"unclassified")
dat <- dat %>%
mutate(Phylum = factor(Phylum, levels = phyla_order))
```
```{r}
dat %>%
ggplot(aes(x = sample_id, y = count)) +
facet_grid(~ fraction + soil, scales = "free_x", space = "free_x") +
geom_bar(aes(fill = Phylum), stat = "identity", position = "fill", width = 1) +
scale_fill_brewer(palette = "Paired") +
scale_y_continuous(name = "Relative abundance",
labels = scales::percent) +
theme(axis.text.x = element_text(angle = 90, size = 6),
axis.text.y = element_text(color = "black"),
strip.text = element_text(face = "bold"),
strip.background = element_blank())
```