-
Notifications
You must be signed in to change notification settings - Fork 10
/
Landscaping.Rmd
executable file
·148 lines (109 loc) · 4.47 KB
/
Landscaping.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
---
title: "Microbiome Landscapes"
author: "Leo Lahti, Sudarshan Shetty et al."
bibliography:
- bibliography.bib
output:
BiocStyle::html_document:
number_sections: no
toc: yes
toc_depth: 4
toc_float: true
self_contained: true
thumbnails: true
lightbox: true
gallery: true
use_bookdown: false
highlight: haddock
---
<!--
%\VignetteEngine{knitr::rmarkdown}
%\VignetteIndexEntry{microbiome tutorial - density}
%\usepackage[utf8]{inputenc}
%\VignetteEncoding{UTF-8}
-->
[Microbiome Landscaping](https://academic.oup.com/femsre/article/doi/10.1093/femsre/fuw045/2979411/Intestinal-microbiome-landscaping-insight-in#58802539) refers to the analysis and illustration of population frequencies. Typically, these are wrappers based on standard ordination methods (for more examples, see [ordination examples](Ordination.html))
## Two-dimensional microbiome landscape
Load example data:
```{r landscaping, message=FALSE, warning=FALSE, eval=TRUE}
library(microbiome)
library(phyloseq)
library(ggplot2)
data(dietswap)
pseq <- dietswap
# Convert to compositional data
pseq.rel <- microbiome::transform(pseq, "compositional")
# Pick core taxa
pseq.core <- core(pseq.rel, detection = 5/100, prevalence = 5/100)
pseq.core <- subset_samples(pseq.core, sex == "female" &
bmi_group == "overweight")
```
## Landscape figure
Visualize the microbiome landscape (sample similarities on two-dimensional projection). When using these tools, kindly cite Shetty et al. FEMS Microbiology Reviews, 41(2):182–199, 2017 [doi:10.1093/femsre/fuw045](https://doi.org/10.1093/femsre/fuw045).
### PCA
```{r landscape_pca, message=FALSE, warning=FALSE, fig.width=8, fig.height=6, fig.show="hold", out.width="400px"}
# PCA with euclidean distance and CLR transformation
p <- plot_landscape(pseq, method = "PCA", transformation = "clr") +
labs(title = paste("PCA / CLR"))
print(p)
```
### PCoA / MDS
```{r landscape_pcoa, message=FALSE, warning=FALSE, fig.width=8, fig.height=6, fig.show="hold", out.width="400px", eval=FALSE}
# PCoA for compositional data with Bray-Curtis distances
p <- plot_landscape(microbiome::transform(pseq.core, "compositional"),
method = "PCoA", distance = "bray") +
labs(title = paste("PCoA / Compositional / Bray-Curtis"))
print(p)
```
### t-SNE
```{r landscape_tsne, message=FALSE, warning=FALSE, fig.width=8, fig.height=6, fig.show="hold", out.width="400px"}
p <- plot_landscape(pseq, "t-SNE",
distance = "euclidean", transformation = "hellinger") +
labs(title = paste("t-SNE / Hellinger / Euclidean"))
print(p)
```
### NMDS
```{r landscape3, message=FALSE, warning=FALSE, fig.width=8, fig.height=6, fig.show="hold", out.width="400px"}
# Landscape plot directly from phyloseq object
p <- plot_landscape(pseq.core, "NMDS", "bray", col = "nationality") +
labs(title = paste("NMDS / Bray-Curtis"))
```
For direct access to the ordination coordinates, use the following:
```{r landscape4, message=FALSE, warning=FALSE, fig.width=8, fig.height=6, fig.show="hold", out.width="400px"}
# Project the samples with the given method and dissimilarity measure.
# Ordinate the data; note that some ordinations are sensitive to random seed
# "quiet" is used to suppress intermediate outputs
set.seed(423542)
x <- pseq.core
quiet(x.ord <- ordinate(x, "NMDS", "bray"))
# Pick the projected data (first two columns + metadata)
proj <- phyloseq::plot_ordination(x, x.ord, justDF=TRUE)
# Rename the projection axes
names(proj)[1:2] <- paste("Comp", 1:2, sep=".")
# Same with a generic data.frame
# (note that random seed will affect the exact ordination)
p <- plot_landscape(proj[, 1:2], col = proj$nationality, legend = T)
print(p)
# Visualize sample names:
ax1 <- names(proj)[[1]]
ax2 <- names(proj)[[2]]
p <- ggplot(aes_string(x = ax1, y = ax2, label = "sample"), data = proj) +
geom_text(size = 2)
print(p)
```
## Abundance histograms (one-dimensional landscapes)
Population densities for Dialister:
```{r hist, fig.width=6, fig.width=8, fig.height=6, fig.show="hold", out.width="400px"}
# Load libraries
library(microbiome)
library(phyloseq)
pseq <- dietswap
# Visualize population densities for specific taxa
plot_density(pseq, "Dialister") + ggtitle("Absolute abundance")
# Same with log10 compositional abundances
x <- microbiome::transform(pseq, "compositional")
tax <- "Dialister"
plot_density(x, tax, log10 = TRUE) +
ggtitle("Relative abundance") +
xlab("Relative abundance (%)")
```