-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathplotForest.Rd
More file actions
210 lines (178 loc) · 6.29 KB
/
plotForest.Rd
File metadata and controls
210 lines (178 loc) · 6.29 KB
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
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/AllGenerics.R, R/plotForest.R
\name{plotForest}
\alias{plotForest}
\alias{plotForest,TreeSummarizedExperiment-method}
\alias{plotForest,SummarizedExperiment-method}
\alias{plotForest,data.frame-method}
\title{Visualize estimated results with forest plots}
\usage{
plotForest(x, ...)
\S4method{plotForest}{TreeSummarizedExperiment}(
x,
by = 1L,
effect.var = "effect",
ci.lower.var = "lower",
ci.upper.var = "upper",
err.var = NULL,
pval.var = "pval",
id.var = "rownames",
label.by = NULL,
order.by = NULL,
facet.by = NULL,
color.by = colour.by,
colour.by = NULL,
conf.level = 0.95,
tree.name = "phylo",
show.tree = TRUE,
...
)
\S4method{plotForest}{SummarizedExperiment}(
x,
by = 1L,
effect.var = "effect",
ci.lower.var = "lower",
ci.upper.var = "upper",
err.var = NULL,
pval.var = "pval",
id.var = "rownames",
label.by = NULL,
order.by = NULL,
facet.by = NULL,
color.by = colour.by,
colour.by = NULL,
conf.level = 0.95
)
\S4method{plotForest}{data.frame}(
x,
effect.var = "effect",
ci.lower.var = "lower",
ci.upper.var = "upper",
err.var = NULL,
pval.var = "pval",
id.var = "rownames",
label.by = NULL,
order.by = NULL,
facet.by = NULL,
color.by = colour.by,
colour.by = NULL,
conf.level = 0.95
)
}
\arguments{
\item{x}{a
\code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}}
object, or a \code{data.frame} object containing statistical estimates.}
\item{...}{additional parameters passed to \code{\link{plotRowTree}}.}
\item{by}{\code{Character scalar}. Determines whether features or samples
data is used for the plot. (Default: \code{"rows"})}
\item{effect.var}{\code{Character scalar}. Specifies the variable of x which
corresponds to the effects or estimated results. (Default: \code{"effect"})}
\item{ci.lower.var}{\code{Character scalar}. Specifies the variable of x
which corresponds to the lower CI boundaries. (Default: \code{"lower"})}
\item{ci.upper.var}{\code{Character scalar}. Specifies the variable of x
which corresponds to the upper CI boundaries. (Default: \code{"upper"})}
\item{err.var}{\code{Character scalar}. Specifies the variable of x which
corresponds to the standard errors associated with \code{effect.var}.
When defined, it overwrites \code{ci.lower.var} and \code{ci.upper.var}.
(Default: \code{"pval"})}
\item{pval.var}{\code{Character scalar}. Specifies the variable of x which
corresponds to the p-values associated with \code{effect.var}.
(Default: \code{"pval"})}
\item{id.var}{\code{Character scalar}. Specifies the variable of x which
corresponds to the observation identifiers. When \code{"rownames"}),
the object rownames are used. (Default: \code{"rownames"})}
\item{label.by}{\code{Character vector}. Specifies the variables of x or
row/colData(x) by which the plot should be labelled. \code{"CI"} and
\code{"P-Value"} are special entries which require either \code{effect.var},
\code{ci.lower.var} and \code{ci.upper.var} or \code{pval.var} to be
specified, respectively. (Default: \code{NULL})}
\item{order.by}{\code{Character scalar}. Specifies the variable of x by which
observations are ordered. If \code{NULL}, the observations are ordered by
the tree structure if available. (Default: \code{NULL})}
\item{facet.by}{\code{Character scalar}. Specifies the variable of x by which
observations are divided into horizontal facets. (Default: \code{NULL})}
\item{color.by}{\code{Character scalar}. Alias to \code{colour.by}.}
\item{colour.by}{\code{Character scalar}. Specifies the variable of x by
which observations are coloured. (Default: \code{NULL})}
\item{conf.level}{\code{Numeric scalar}. Specifies the confidence level of
the interval when inferred from \code{err.var}. It is ignored when
\code{ci.lower.var} and \code{ci.upper.var} are defined.
(Default: \code{0.95})}
\item{tree.name}{\code{Character scalar}. Specifies a row/colTree from x.
(Default: \code{"phylo"})}
\item{show.tree}{\code{Logical scalar}. Should the tree structure of the data
be shown next to the forest plot?}
}
\value{
a \code{\link[ggplot2:ggplot]{ggplot}} object.
}
\description{
\code{plotForest()} creates a feature- or sample-wise forest plot, showing
estimated results from a statistical test with their confidence intervals.
Additionally, the plot can be enriched with the tree structure and labelled
with Confidence Intervals (CIs), p-values and other side information.
}
\examples{
library(mia)
library(maaslin3)
# Import dataset
data("Tengeler2020", package = "mia")
tse <- Tengeler2020
# Agglomerate by genus and subset by prevalence
tse <- subsetByPrevalent(tse, rank = "Genus", prevalence = 10/100)
# Transform count assay to relative abundances
tse <- transformAssay(tse, assay.type = "counts", method = "relabundance")
# Run maaslin3
maaslin3_out <- maaslin3(
input_data = tse,
output = "maaslin_results",
formula = "~ patient_status",
)
# Retrieve abundance results
maaslin3_abund <- maaslin3_out$fit_data_abundance$results
maaslin3_abund <- maaslin3_abund[!is.na(maaslin3_abund$coef), ]
# Visualize abundance results
plotForest(
maaslin3_abund,
effect.var = "coef",
err.var = "stderr",
pval.var = "qval_joint",
id.var = "feature",
label.by = c("CI", "P-Value"),
order.by = "coef"
)
# Add abundance results to TreeSE rowData
rownames(maaslin3_abund) <- maaslin3_abund$feature
tax_order <- match(rownames(tse), rownames(maaslin3_abund))
rowData(tse) <- cbind(rowData(tse), maaslin3_abund[tax_order, ])
# Visualise abundance results with tree structure
plotForest(
tse,
effect.var = "coef",
err.var = "stderr",
pval.var = "qval_joint",
label.by = c("CI", "P-Value")
)
# Retrieve prevalence results
maaslin3_prev <- maaslin3_out$fit_data_prevalence$results
maaslin3_prev <- maaslin3_prev[!is.na(maaslin3_prev$coef), ]
# Combine abundance and prevalence results
maaslin3_res <- rbind(maaslin3_abund, maaslin3_prev)
maaslin3_res$association <- c(
rep("Abundance", nrow(maaslin3_abund)),
rep("Prevalence", nrow(maaslin3_prev))
)
# Visualize combined results
plotForest(
maaslin3_res,
effect.var = "coef",
err.var = "stderr",
pval.var = "qval_joint",
id.var = "feature",
label.by = c("CI", "P-Value"),
order.by = "coef",
facet.by = "association",
colour.by = "association"
)
}