Plot a heatmap of funprofiler KO or pathway abundances
Source:R/funprofiler_heatmap.R
funprofiler_heatmap.RdDraws a samples x functions heatmap with ggplot2::geom_tile().
Abundances are first summed within each sample at the chosen feature
level (each KO, or all KOs of a KEGG pathway, pathway class or category),
and the top_n features with the highest mean abundance across samples
are shown.
Usage
funprofiler_heatmap(
data,
feature = "ko",
abundance = "relative_abundance",
sample = "sample_id",
group = NULL,
sample_label = NULL,
feature_label = NULL,
feature_label_wrap = TRUE,
top_n = 30,
transform = c("none", "log10", "clr"),
pseudocount = NULL,
cluster = c("none", "features", "samples", "both"),
split = NULL,
show_unassigned = TRUE,
palette = "viridis"
)Arguments
- data
A data frame from
funprofiler_aggregate(), or any data frame with sample, feature and abundance columns, one row per sample and KO, with a single profile per sample.- feature
Column to aggregate and label the rows by:
"ko"(the default), or with KEGG annotation"pathway","pathway_class"or"pathway_category"; any other column works too. Missing values are shown as"Unassigned".- abundance
Abundance column:
"relative_abundance"(%, the default) or"abundance"(proportion).- sample
Column identifying the sample. Defaults to
"sample_id".- group
Optional column of sample groups (e.g.
"isolation_source"or"host_subject_id"). Samples are split into side-by-side panels by group.- sample_label
Optional column to label the samples with on the x axis, instead of
sample. It must have one value per sample.- feature_label
Optional column to label the features with on the y axis, with one value per feature. Defaults to
"ko_label"(e.g."K00845 glk") whenfeature = "ko"and that column exists.- feature_label_wrap
If
TRUE(the default), feature labels on the y axis that are longer than 40 characters, such as KEGG's longer pathway names ("Biosynthesis of siderophore group nonribosomal peptides") or KOs with many gene symbols, are wrapped onto two lines (at about 40 characters, or wider for labels too long to fit two lines of 40). This leaves more of the plot's width for the tiles, so that narrow panels and sample labels fit, but two-line labels need taller rows: if neighbouring labels overlap, make the plot taller.FALSEkeeps each label on one line. Applies to anyfeature, and tofeature_label.- top_n
Number of features to show, those with the highest mean abundance across samples.
Infshows all.- transform
"none","log10"or"clr"; see Details.- pseudocount
Value that replaces zeros before the CLR transform. Defaults to half the smallest non-zero summed abundance.
- cluster
Order features and/or samples by hierarchical clustering (
stats::hclust()on Euclidean distances of the plotted values):"none"(the default),"features","samples"or"both". Unclustered features are ordered by mean abundance, and unclustered samples as they appear indata. Withgroup, samples are clustered within each panel.- split
Separator of multiple values in a
featurecell, each of which gets the KO's abundance.NULL(the default) uses"; "for"pathway","pathway_class"and"pathway_category"and no splitting otherwise;FALSEnever splits.- show_unassigned
If
FALSE, the"Unassigned"row (KOs with a missingfeature, e.g. in no KEGG pathway) is not shown, though it is still part of each sample's composition for the CLR.- palette
A viridis palette option for the fill scale.
Value
A ggplot object. The plotted values are in its data element,
with columns sample, feature, abundance and value.
Details
Pathways. After funprofiler_aggregate() with kegg, feature can be
"pathway", "pathway_class" or "pathway_category". These columns list
all of a KO's pathways (separated by "; "), and a KO counts towards each
of them, so a pathway's abundance is the summed abundance of its KOs found
in the sample. Because KOs are shared between pathways, pathway abundances
of a sample add up to more than 100%. KOs in no pathway are shown as
"Unassigned"; hide that row with show_unassigned = FALSE (it still
counts in the CLR), or filter data (e.g. !is.na(data$pathway)) to drop
those KOs altogether.
transform sets what the tiles show:
"none"the abundance (%). Features not detected in a sample are drawn in grey.
"log10"log10 of the abundance. Features not detected in a sample are drawn in grey.
"clr"the centred log-ratio (CLR) of the abundance, computed per sample over all features at
feature(not only thetop_nshown), after replacing zeros withpseudocount. Undetected features get a (low) CLR value rather than grey.
See also
funprofiler_aggregate() to make data, and
funprofiler_feature_plot() to focus on a single KO or pathway.
Examples
profiles <- funprofiler_aggregate(funprofiler_example("profiles"),
metadata = funprofiler_example("runs"))
funprofiler_heatmap(profiles, group = "isolation_source")
# CLR-transformed, clustered, samples labelled by subject
profiles$label <- paste(profiles$host_subject_id, profiles$sample_id)
funprofiler_heatmap(profiles, transform = "clr", sample_label = "label",
cluster = "both")
if (FALSE) { # \dontrun{
# KEGG pathways
profiles <- funprofiler_aggregate(
funprofiler_example("profiles"), metadata = funprofiler_example("runs"),
kegg = funprofiler_kegg("data/kegg/ko00001.keg")
)
funprofiler_heatmap(profiles, feature = "pathway", top_n = 25,
transform = "log10", group = "isolation_source")
} # }