Creates a heatmap from an assay stored in a SummarizedExperiment or TreeSummarizedExperiment. Features are shown as rows and samples as columns.

plotHeatmap(x, ...)

# S4 method for class 'TreeSummarizedExperiment'
plotHeatmap(
  x,
  assay.type = NULL,
  row.var = NULL,
  col.var = NULL,
  scale = FALSE,
  center = FALSE,
  tree.name = "phylo",
  show.tree = FALSE,
  ...
)

# S4 method for class 'SummarizedExperiment'
plotHeatmap(
  x,
  assay.type = NULL,
  row.var = NULL,
  col.var = NULL,
  scale = FALSE,
  center = FALSE,
  ...
)

Arguments

x

a SummarizedExperiment object.

...

Additional parameters controlling the visualization. When show.tree = TRUE, additional arguments are passed to plotRowTree to control the appearance of the tree. Additional parameters include, for example:

assay.type

Character scalar value defining which assay data to use. (Default: "relabundance")

row.var

NULL or character vector. Variables from rowData(x) used for row facetting. (Default: NULL)

col.var

NULL or character vector. Variables from colData(x) used for column facetting. (Default: NULL)

scale

Logical scalar. Should assay values be scaled for each feature across samples? (Default: FALSE)

center

Logical scalar. Should assay values be centered for each feature across samples? (Default: FALSE)

tree.name

Character scalar. Name of the row tree to display when x is a TreeSummarizedExperiment. (Default: "phylo")

show.tree

Logical scalar. Should the row tree be displayed? Only available for TreeSummarizedExperiment. (Default: TRUE)

Value

A ggplot2 object. If show.tree = TRUE, the returned object is a combined patchwork object containing the row tree and the heatmap.

Details

plotHeatmap visualizes values from an assay as a heatmap. Values can be optionally centered and/or scaled across samples for each feature, which is useful for highlighting relative abundance patterns rather than absolute abundances.

Additional variables from rowData(x) and colData(x) can be used to facet the heatmap. When multiple row or column variables are provided, nested facets are created using ggh4x.

For TreeSummarizedExperiment objects, a row tree can be displayed alongside the heatmap. When a tree is shown, only leaf nodes are plotted and the heatmap rows are reordered to match the tree tip order.

See also

Examples

data(GlobalPatterns)
tse <- GlobalPatterns

tse <- agglomerateByPrevalence(tse, rank = "Class")

# Plot raw counts
plotHeatmap(
    tse,
    assay.type = "counts"
)
#> Error in plotHeatmap(tse, assay.type = "counts"): argument "features" is missing, with no default

# Scale and center each feature
plotHeatmap(
    tse,
    assay.type = "counts",
    scale = TRUE,
    center = TRUE
)
#> Error in plotHeatmap(tse, assay.type = "counts", scale = TRUE, center = TRUE): argument "features" is missing, with no default

# Facet samples by metadata
plotHeatmap(
    tse,
    assay.type = "counts",
    col.var = "SampleType"
)
#> Error in plotHeatmap(tse, assay.type = "counts", col.var = "SampleType"): argument "features" is missing, with no default

# Add phylogeny
plotHeatmap(
    tse,
    assay.type = "counts",
    show.tree = TRUE
)
#> Error in plotHeatmap(tse, assay.type = "counts", show.tree = TRUE): argument "features" is missing, with no default