Draws a samples x taxa heatmap with ggplot2::geom_tile(). Abundances
are first summed within each sample at the chosen taxonomic rank (so,
for example, all genomes of a genus are added together), and the top_n
taxa with the highest mean abundance across samples are shown.
Usage
sylph_heatmap(
data,
rank = "species",
abundance = "taxonomic_abundance",
sample = "sample_id",
group = NULL,
sample_label = NULL,
feature_label_wrap = TRUE,
top_n = 30,
transform = c("none", "log10", "clr"),
pseudocount = NULL,
cluster = c("none", "taxa", "samples", "both"),
palette = "viridis",
italic = NULL
)Arguments
- data
A data frame from
sylph_aggregate(), or any data frame with sample, taxon and abundance columns, one row per sample and genome.- rank
Column to aggregate and label taxa by, e.g.
"species"(the default),"genus","family","organism"or"accession". Missing values are shown as"Unclassified".- abundance
Abundance column:
"taxonomic_abundance"(the default) or"sequence_abundance".- 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_wrap
If
TRUE(the default), taxon labels on the y axis that are longer than 40 characters are wrapped onto two lines, at about 40 characters, or wider for labels too long to fit two lines of 40. Labels break at spaces (e.g. "Faecaligallichristensenella" / "faecipullorum") or after semicolons, so GTDB lineages (rank = "gtdb_taxonomy") break between ranks, with the semicolon at the end of the first line. A label with nowhere to break is left whole. Wrapping 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.- top_n
Number of taxa 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 abundance in
data.- cluster
Order taxa and/or samples by hierarchical clustering (
stats::hclust()on Euclidean distances of the plotted values):"none"(the default),"taxa","samples"or"both". Unclustered taxa are ordered by mean abundance, and unclustered samples as they appear indata. Withgroup, samples are clustered within each panel.- palette
A viridis palette option for the fill scale.
- italic
If
TRUE, taxon labels are set in italics. Defaults toTRUEforrank"genus","species"or"organism".
Value
A ggplot object. The plotted values are in its data element,
with columns sample, taxon, abundance and value.
Details
transform sets what the tiles show:
"none"the abundance (%). Taxa not detected in a sample are drawn in grey.
"log10"log10 of the abundance. Taxa not detected in a sample are drawn in grey.
"clr"the centred log-ratio (CLR) of the abundance, computed per sample over all taxa at
rank(not only thetop_nshown), after replacing zeros withpseudocount. Undetected taxa get a (low) CLR value rather than grey.
See also
sylph_aggregate() to make data, and sylph_taxon_plot() to
focus on a single taxon.
Examples
profiles <- sylph_aggregate(sylph_example("profiles"),
metadata = sylph_example("runs"))
sylph_heatmap(profiles, group = "isolation_source")
# genus level, log10 scale, clustered taxa
sylph_heatmap(profiles, rank = "genus", top_n = 15, transform = "log10",
cluster = "taxa", group = "isolation_source")
# CLR-transformed species abundances, samples labelled by subject
profiles$label <- paste(profiles$host_subject_id, profiles$sample_id)
sylph_heatmap(profiles, transform = "clr", sample_label = "label",
cluster = "both")