Skip to contents

Draws a features-by-cells expression heatmap with one or more metadata annotation bars on top, built on Heatmap. Columns are ordered by a chosen metadata variable (e.g. a trajectory value) independently of the annotation bars, which makes it suited to trajectory / differential-expression heatmaps where cells are ordered along a continuous axis while still displaying a categorical annotation (something the grouped DoHeatmap cannot do).

Usage

PlotAnnotatedHeatmap(
  object,
  features,
  sort.by,
  anno.var = NULL,
  anno.colors = NULL,
  assay = NULL,
  layer = "scale.data",
  hm.limit = c(-2, 0, 2),
  hm.colors = c("#4575b4", "white", "#d73027"),
  cluster.rows = FALSE,
  cluster.columns = FALSE,
  show.column.names = FALSE,
  row.font.size = 12,
  ...
)

Arguments

object

A Seurat object.

features

Character vector of features (rows of the heatmap). Features absent from the requested layer are dropped with a warning.

sort.by

One or more metadata column names used to order the cells (columns of the heatmap). Multiple names are applied in order as tie-breakers.

anno.var

Optional character vector of metadata column names, each drawn as a top annotation bar. NULL (default) draws no annotation.

anno.colors

Optional list of colors for anno.var, one element per variable (named by variable, or positionally matched to anno.var). For a categorical variable supply at least one color per level; for a numeric variable supply exactly three colors (min, median, max). NULL entries use defaults.

assay

Assay to pull expression from. Defaults to the object's default assay.

layer

Layer to pull expression from. Default is "scale.data".

hm.limit

Numeric vector of three breakpoints for the heatmap color gradient (low, mid, high). Default is c(-2, 0, 2).

hm.colors

Three colors mapped to hm.limit. Values beyond the range saturate to the endpoint colors. Default is a blue-white-red gradient.

cluster.rows

Whether to cluster rows (features). Default is FALSE.

cluster.columns

Whether to cluster columns (cells). Default is FALSE; clustering overrides the sort.by ordering.

show.column.names

Whether to show cell names. Default is FALSE.

row.font.size

Font size for row (feature) names. Default is 12.

...

Additional arguments passed to Heatmap.

Value

A Heatmap-class object, which draws when printed. For the horizontal, bottom-placed legend layout use ComplexHeatmap::draw(ht, heatmap_legend_side = "bottom").

Details

This is an independent implementation whose interface is inspired by Scillus::plot_heatmap; it does not reuse that package's code.

Examples

if (FALSE) { # \dontrun{
PlotAnnotatedHeatmap(
  object = sample_obj,
  features = top_genes,
  sort.by = "pseudotime",
  anno.var = "Disease"
)
} # }