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 = taxonomyRanks(x)[1],
features = NULL,
order_rank_by = c("name", "abund", "revabund"),
order_sample_by = NULL,
decreasing = TRUE,
use_relative = TRUE,
layout = c("bar", "point"),
one_facet = TRUE,
ncol = 2,
scales = "fixed",
assay.type = assay_name,
assay_name = "counts",
...
)
x |
a
|
... |
additional parameters for plotting. See
|
rank |
a single |
features |
a single |
order_rank_by |
How to order abundance value: By name (“name”) for sorting the taxonomic labels alphabetically, by abundance (“abund”) to sort by abundance values or by a reverse order of abundance values (“revabund”). |
order_sample_by |
A single character value from the chosen rank of abundance
data or from |
decreasing |
TRUE or FALSE: If the |
use_relative |
|
layout |
Either “bar” or “point”. |
one_facet |
Should the plot be returned in on facet or split into
different facet, one facet per different value detect in |
ncol, scales |
if |
assay.type |
a |
assay_name |
a single |
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
features present.
a ggplot
object or list of two
ggplot
objects, if features
are added to
the plot.
data(GlobalPatterns, package="mia")
se <- GlobalPatterns
## Plotting abundance using the first taxonomic rank as default
plotAbundance(se, assay.type="counts")
## Using "Phylum" as rank
plotAbundance(se, assay.type="counts", rank = "Phylum", add_legend = FALSE)
## If rank is set to NULL plotAbundance behaves like plotExpression
plotAbundance(se, assay.type="counts", rank = NULL,
features = head(rownames(se)))
## A feature from colData or taxon from chosen rank can be used for ordering samples.
plotAbundance(se, assay.type="counts", rank = "Phylum",
order_sample_by = "Bacteroidetes")
## Features from colData can be plotted together with abundance plot.
# Returned object is a list that includes two plot; other visualizes abundance
# other features.
plot <- plotAbundance(se, assay.type = "counts", rank = "Phylum",
features = "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(se, assay.type = "counts", rank = "Phylum",
features = "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
se <- transformAssay(se, method="relabundance")
se_phylum <- agglomerateByRank(se, rank ="Phylum", onRankOnly=TRUE)
top_taxa <- getTopTaxa(se_phylum,top = 5, assay.type = "relabundance")
# Renaming the "Phylum" rank to keep only top taxa and the rest to "Other"
phylum_renamed <- lapply(rowData(se)$Phylum,
function(x){if (x %in% top_taxa) {x} else {"Other"}})
rowData(se)$Phylum <- as.character(phylum_renamed)
# Compositional barplot
plotAbundance(se, assay.type="relabundance", rank = "Phylum",
order_rank_by="abund", order_sample_by = "Bacteroidetes")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.