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, ...)

Arguments

object

Object.

assay

vector(1). Assay name or index position.

interestingGroups

character. Groups of interest to use for visualization. Corresponds to factors describing the columns of the object.

scale

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

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.

title

character(1). Title.

...

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

Value

pheatmap.

Methods (by class)

  • SingleCellExperiment: Applies pseudobulk() calculation to average gene expression at sample level prior to plotting.
    Passes ... to SummarizedExperiment method.

Note

Updated 2019-08-27.

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