Construct a simple heatmap.

plotHeatmap(object, ...)

# S4 method for SummarizedExperiment
plotHeatmap(object, assay = 1L,
  interestingGroups = NULL, scale = c("none", "row", "column"),
  clusteringMethod = "ward.D2", clusterRows = FALSE,
  clusterCols = FALSE, showRownames = FALSE, showColnames = TRUE,
  treeheightRow = 50L, treeheightCol = 50L, color = getOption(x =
  "acid.heatmap.color", default = acidplots::synesthesia),
  legendColor = getOption(x = "acid.heatmap.color", default =
  acidplots::synesthesia), breaks = NULL, legendBreaks = NULL,
  borderColor = NULL, title = NULL, ...)

# S4 method for SingleCellExperiment
plotHeatmap(object, assay = 1L,
  interestingGroups = NULL, scale = c("none", "row", "column"),
  clusteringMethod = "ward.D2", clusterRows = FALSE,
  clusterCols = FALSE, showRownames = FALSE, showColnames = TRUE,
  treeheightRow = 50L, treeheightCol = 50L, color = getOption(x =
  "acid.heatmap.color", default = acidplots::synesthesia),
  legendColor = getOption(x = "acid.heatmap.color", default =
  acidplots::synesthesia), breaks = NULL, legendBreaks = NULL,
  borderColor = NULL, title = NULL, ...)

Arguments

object

Object.

assay

vector(1). Name or index of count matrix slotted in assays(). When passing in a string, the name must be defined in assayNames().

interestingGroups

character. Groups of interest that define the samples. If left unset, defaults to sampleName.

scale

character(1). Whether the values should be centered and scaled in either the row or column direction ("row", "column"), or remain unscaled ("none").

clusteringMethod

character(1). Clustering method. Accepts the same values as hclust().

clusterRows, clusterCols

logical(1). Arrange with hierarchical clustering.

showRownames, showColnames

logical(1). Show row or column names.

treeheightRow, treeheightCol

integer(1). Size of the row and column dendrograms. Use 0 to disable.

color

function, character, or NULL. Hexadecimal color function or values to use for plot.

We generally recommend these hexadecimal functions from the viridis package, in addition to our synesthesia() palette:

Alternatively, colors can be defined manually using hexadecimal values (e.g. c("#FF0000", "#0000FF")), but this is not generally recommended. Refer to the RColorBrewer package for hexadecimal color palettes that may be suitable. If set NULL, will use the default pheatmap colors.

legendColor

function or NULL. Hexadecimal color function to use for legend labels. Note that hexadecimal values are not supported. If set NULL, will use the default pheatmap colors.

breaks

numeric or NULL. A sequence of numbers that covers the range of values in the matrix. Must be 1 element longer than the color vector, which is handled internally automatically, differing from the behavior in pheatmap.

legendBreaks

numeric or NULL. Numeric vector of breakpoints for the color legend.

borderColor

character(1) or NULL. Border color. Disabled by default for improved aesthetics.

title

character(1). Plot title.

...

Passthrough arguments to pheatmap(). The argument names must be formatted in camel case, not snake case.

Value

pheatmap.

Scaling

Here we're scaling simply by calculating the standard score (z-score).

  • mu: mean.

  • sigma: standard deviation.

  • x: raw score (e.g. count matrix).

  • z: standard score (z-score).

z = (x - mu) / sigma

See also:

  • pheatmap:::scale_rows().

  • scale() for additional scaling approaches.

Hierarchical clustering

Row- and column-wise hierarchical clustering is performed when clusterRows and/or clusterCols are set to TRUE. Internally, this calls hclust(), and defaults to the Ward method.

Automatic hierarchical clustering of rows and/or columns can error for some datasets. When this occurs, you'll likely see this error:

Error in hclust(d, method = method) :
NA/NaN/Inf in foreign function call

In this case, either set clusterRows and/or clusterCols to FALSE, or you can attempt to pass an hclust object to these arguments. This is recommended as an alternate approach to be used with pheatmap(), which is called internally by our plotting code. Here's how this can be accomplished:

mat <- assay(mat)
dist <- dist(mat)
hclust <- hclust(dist, method = "ward.D2")

See also

Examples

data(rse, sce, package = "acidtest") ## SummarizedExperiment ==== plotHeatmap(rse)
## Disable column clustering. plotHeatmap(rse, clusterCols = FALSE)
## Using pheatmap default colors. plotHeatmap(rse, color = NULL, legendColor = NULL)
## Using hexadecimal color input. color <- RColorBrewer::brewer.pal(n = 11L, name = "PuOr") color <- grDevices::colorRampPalette(color)(256L) plotHeatmap(rse, color = color)
## SingleCellExperiment ==== plotHeatmap(sce)
#> Aggregating counts using mean().