plotAbundance | R Documentation |
plotAbundance
plots the abundance on a selected taxonomic rank.
Since this probably makes sense only for relative abundance data, the
assay used by default is expected to be in the slot ‘relabundance’.
If only ‘counts’ is present, the relative abundance is computed.
plotAbundance(x, ...)
## S4 method for signature 'SummarizedExperiment'
plotAbundance(
x,
rank = NULL,
col.var = features,
features = NULL,
order.row.by = order_rank_by,
order_rank_by = c("name", "abund", "revabund"),
order.col.by = order_sample_by,
order_sample_by = NULL,
decreasing = TRUE,
layout = c("bar", "point"),
one.facet = one_facet,
one_facet = TRUE,
ncol = 2,
scales = "fixed",
assay.type = assay_name,
assay_name = "counts",
...
)
x |
a
|
... |
additional parameters for plotting.
See |
rank |
|
col.var |
|
features |
Deprecated. Use |
order.row.by |
|
order_rank_by |
Deprecated. Use |
order.col.by |
|
order_sample_by |
Deprecated. Use |
decreasing |
|
layout |
|
one.facet |
|
one_facet |
Deprecated. Use |
ncol |
|
scales |
|
assay.type |
|
assay_name |
Deprecate. Use |
Subsetting to rows of interested and ordering of those is expected to be done
outside of this functions, e.g. x[1:2,]
. This will plot data of all
col.var present.
a ggplot
object or list of two
ggplot
objects, if col.var
are added to
the plot.
data(GlobalPatterns, package="mia")
tse <- GlobalPatterns
## If rank is set to NULL (default), agglomeration is not done. However, note
## that there is maximum number of rows that can be plotted. That is why
## we take sample from the data.
set.seed(26348)
sample <- sample(rownames(tse), 20)
tse_sub <- tse[sample, ]
# Apply relative transformation
tse_sub <- transformAssay(tse_sub, method = "relabundance")
plotAbundance(tse_sub, assay.type = "relabundance")
## Plotting counts using the first taxonomic rank as default
plotAbundance(
tse, assay.type="counts", rank = "Phylum") +
labs(y="Counts")
## Using "Phylum" as rank. Apply relative transformation to "counts" assay.
plotAbundance(
tse, assay.type="counts", rank = "Phylum", add_legend = FALSE,
as.relative = TRUE)
# Apply relative transform
tse <- transformAssay(tse, method = "relabundance")
## A feature from colData or taxon from chosen rank can be used for ordering
## samples.
plotAbundance(tse, assay.type="relabundance", rank = "Phylum",
order.col.by = "Bacteroidetes")
## col.var from colData can be plotted together with abundance plot.
# Returned object is a list that includes two plot; other visualizes
## abundance other col.var.
plot <- plotAbundance(tse, assay.type = "relabundance", rank = "Phylum",
col.var = "SampleType")
# These two plots can be combined with wrap_plots function from patchwork
# package
library(patchwork)
wrap_plots(plot, ncol = 1)
## Same plot as above but showing sample IDs as labels for the x axis on the
## top plot
plot[[1]] <- plotAbundance(tse, assay.type = "relabundance", rank = "Phylum",
col.var = "SampleType", add.legend = FALSE,
add.x.text = TRUE)[[1]] +
theme(axis.text.x = element_text(angle = 90))
wrap_plots(plot, ncol = 1, heights = c(0.8,0.2))
## Compositional barplot with top 5 taxa and samples sorted by
## "Bacteroidetes"
# Getting top taxa on a Phylum level
tse <- transformAssay(tse, method="relabundance")
tse_phylum <- agglomerateByRank(tse, rank ="Phylum", onRankOnly=TRUE)
top_taxa <- getTop(tse_phylum,top = 5, assay.type = "relabundance")
# Renaming the "Phylum" rank to keep only top taxa and the rest to "Other"
phylum_renamed <- lapply(rowData(tse)$Phylum,
function(x){if (x %in% top_taxa) {x} else {"Other"}})
rowData(tse)$Phylum <- as.character(phylum_renamed)
# Compositional barplot
plotAbundance(tse, assay.type="relabundance", rank = "Phylum",
order.row.by="abund", order.col.by = "Bacteroidetes")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.