-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11.PCoA.Rmd
41 lines (32 loc) · 1.25 KB
/
11.PCoA.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
---
title: "PCoA"
output:
pdf_document:
keep_tex: yes
---
```{r, setup, include=FALSE}
knitr::opts_chunk$set(message=FALSE, warning=FALSE, eval=FALSE, tidy.opts=list(width.cutoff=20), tidy=TRUE, wrap=TRUE)
```
In this section, we build beta diversity PCoA plots using the core metrics calculated in Qiime2.
Make any character vectors in your metadata into factors for plotting purposes.
```{r}
metadata$<variable1> <-factor(metadata$<variable1>)
metadata$<variable2> <-factor(metadata$<variable2>)
metadata$<variable3> <-factor(metadata$<variable3>)
```
Here we plot the Weighted UniFrac metric as an example in the PC-plots.
- Choose metadata variables for size and color differentiation.
- Choose the beta diversity metric and the principal components you want to plot.
- Facet wrap by selected variable to combine plots.
```{r}
<xx_wunifrac>$data$Vectors %>%
select(SampleID, PC1, PC2, PC3) %>%
left_join(metadata, by=c("SampleID"="<metadata sample ID>")) %>%
ggplot(aes(x=PC1, y=PC2, color=<variable1>, size=<variable2>)) +
geom_point(alpha=0.5) +
theme_q2r() +
scale_size_discrete(name="<variable2>") +
scale_color_viridis_d(name="<variable1>") +
facet_wrap(.~<variable3>)
#ggsave("PCoA_xx_wu.jpg", height=4.5, width=5.5, device="jpg")
```