plotHeatmap: Heatmap

plotHeatmapR Documentation

Heatmap

Description

Heatmap

Usage

plotHeatmap(object, ...)

## S4 method for signature 'SingleCellExperiment'
plotHeatmap(object, ...)

## S4 method for signature 'SummarizedExperiment'
plotHeatmap(
  object,
  assay = 1L,
  interestingGroups = NULL,
  scale = c("row", "column", "none"),
  clusteringMethod = "ward.D2",
  clusterRows = TRUE,
  clusterCols = TRUE,
  showRownames = isTRUE(nrow(object) <= 30L),
  showColnames = TRUE,
  treeheightRow = 50L,
  treeheightCol = 50L,
  color = getOption(x = "acid.heatmap.color", default = AcidPlots::blueYellow),
  legendColor = getOption(x = "acid.heatmap.legend.color", default =
    AcidPlots::synesthesia),
  breaks = seq(from = -3L, to = 3L, by = 0.25),
  legendBreaks = seq(from = -3L, to = 3L, by = 1L),
  borderColor = NULL,
  title = NULL,
  convertGenesToSymbols = showRownames,
  ...
)

Arguments

object

Object.

...

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

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:

  • viridis::viridis().

  • viridis::inferno().

  • viridis::magma().

  • viridis::plasma().

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.

convertGenesToSymbols

logical(1). Attempt to automatically convert gene identifiers to gene symbols. Only applies when object contains mappings defined in rowRanges.

Value

Plot.

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")

Note

Updated 2021-05-17.

Author(s)

Michael Steinbaugh, Rory Kirchner

See Also

  • pheatmap::pheatmap().

  • RColorBrewer::brewer.pal().

  • stats::cor().

  • stats::hclust().

Examples

data(
    RangedSummarizedExperiment,
    SingleCellExperiment_splatter,
    package = "AcidTest"
)

## SummarizedExperiment ====
object <- RangedSummarizedExperiment
## Row scaling requires non-zero rows.
object <- AcidGenerics::nonzeroRowsAndCols(object)

## Symmetric row-scaled breaks (recommended).
plotHeatmap(
    object,
    scale = "row",
    color = AcidPlots::blueYellow,
    breaks = seq(from = -2L, to = 2L, by = 0.25),
    legendBreaks = seq(from = -2L, to = 2L, by = 1L)
)

## Using custom hexadecimal color input.
if (goalie::isInstalled("RColorBrewer")) {
    color <- rev(RColorBrewer::brewer.pal(n = 11L, name = "PuOr"))
    color <- grDevices::colorRampPalette(color)
    head(color)
    plotHeatmap(
        object = object,
        scale = "row",
        color = color,
        breaks = seq(from = -2L, to = 2L, by = 0.25),
        legendBreaks = seq(from = -2L, to = 2L, by = 1L)
    )
}

## SingleCellExperiment ====
object <- SingleCellExperiment_splatter
## Row scaling requires non-zero rows.
object <- AcidGenerics::nonzeroRowsAndCols(object)
plotHeatmap(object)

acidgenomics/acidplots documentation built on April 1, 2024, 7:37 p.m.