heatmap.2x: Enhanced Heat Map (with annotation matrices)

Description Usage Arguments Value Examples

Description

A heat map is a false color image (basically image(t(x))) with a dendrogram added to the left side and/or to the top. Typically, reordering of the rows and columns according to some set of values (row or column means) within the restrictions imposed by the dendrogram is carried out. This heatmap provides a number of extensions to the standard R heatmap and enhanced heatmap.2 function.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
heatmap.2x(x, Rowv = TRUE, Colv = if (symm) "Rowv" else TRUE,
  distfun = dist, hclustfun = hclust, dendrogram = c("both", "row",
  "column", "none"), reorderfun = function(d, w) reorder(d, w),
  symm = FALSE, nodeParRow = NULL, nodeParCol = NULL,
  edgeParRow = NULL, edgeParCol = NULL, scale = c("none", "row",
  "column"), na.rm = TRUE, revC = identical(Colv, "Rowv"), add.expr,
  breaks = NULL, symbreaks = any(x < 0, na.rm = TRUE) || scale !=
  "none", col = bluered(50), colsep, rowsep, sepcolor = "white",
  sepwidth = c(0.05, 0.05), cellnote, notecex = 1, notecol = "cyan",
  na.color = par("bg"), trace = c("column", "row", "both", "none"),
  tracecol = "cyan", hline = median(breaks), vline = median(breaks),
  linecol = tracecol, margins = c(5, 5), ColSideColors, RowSideColors,
  cexRow = 0.2 + 1/log10(nr), cexCol = 0.2 + 1/log10(nc),
  labRow = NULL, labCol = NULL, cexLab = 1, srtRow = NULL,
  srtCol = NULL, adjRow = c(0, NA), adjCol = c(NA, 0),
  offsetRow = 0.5, offsetCol = 0.5, offsetLabRow = 0,
  offsetLabCol = 0, colRow = NULL, colCol = NULL, key = TRUE,
  keysize = 1.5, density.info = c("histogram", "density", "none"),
  denscol = tracecol, symkey = any(x < 0, na.rm = TRUE) || symbreaks,
  densadj = 0.25, key.title = NULL, key.xlab = NULL,
  key.ylab = NULL, key.xtickfun = NULL, key.ytickfun = NULL,
  key.par = list(), main = NULL, xlab = NULL, ylab = NULL,
  lmat = NULL, lhei = NULL, lwid = NULL, extrafun = NULL, ...)

Arguments

x

numeric matrix of the values to be plotted.

Rowv

determines if and how the row dendrogram should be reordered. By default, it is TRUE, which implies dendrogram is computed and reordered based on row means. If NULL or FALSE, then no dendrogram is computed and no reordering is done. If a dendrogram dendrogram, then it is used "as-is", ie without any reordering. If a vector of integers, then dendrogram is computed and reordered based on the order of the vector.

Colv

determines if and how the column dendrogram should be reordered. Has the options as the Rowv argument above and additionally when x is a square matrix, Colv="Rowv" means that columns should be treated identically to the rows.

distfun

function used to compute the distance (dissimilarity) between both rows and columns. Defaults to dist.

hclustfun

function used to compute the hierarchical clustering when Rowv or Colv are not dendrograms. Defaults to hclust.

dendrogram

character string indicating whether to draw 'none', 'row', 'column' or 'both' dendrograms. Defaults to 'both'. However, if Rowv (or Colv) is FALSE or NULL and dendrogram is 'both', then a warning is issued and Rowv (or Colv) arguments are honoured.

reorderfun

function(d, w) of dendrogram and weights for reordering the row and column dendrograms. The default uses stats-packagestatsreorder.dendrogram

symm

logical indicating if x should be treated symmetrically; can only be true when x is a square matrix.

nodeParRow

Row dendrogram plotting (see plot.dendrogram: a list of parameters to use for the nodes (see ?points). Default value is NULL. The list may contain components named pch, cex, col, xpd, and/or bg each of which can have length two for specifying separate attributes for inner nodes and leaves.

nodeParCol

Column dendrogram plotting: same inputs as nodeParRow

edgeParRow

Row dendrogram plotting (see plot.dendrogram: a list of parameters to use for the edge segments (see ?segments). The list may contain components named col, lty and lwd (for the segments). As with nodePar, each can have length two for differentiating leaves and inner nodes.

edgeParCol

Column dendrogram plotting: same inputs as edgeParRow

scale

character indicating if the values should be centered and scaled in either the row direction or the column direction, or none. The default is "none".

na.rm

logical indicating whether NA's should be removed.

revC

logical indicating if the column order should be reversed for plotting, such that e.g., for the symmetric case, the symmetry axis is as usual.

add.expr

expression that will be evaluated after the call to image. Can be used to add components to the plot.

breaks

(optional) Either a numeric vector indicating the splitting points for binning x into colors, or a integer number of break points to be used, in which case the break points will be spaced equally between min(x) and max(x).

symbreaks

Boolean indicating whether breaks should be made symmetric about 0. Defaults to TRUE if the data includes negative values, and to FALSE otherwise.

col

colors used for the image. Defaults to heat colors (heat.colors). Color functions (in gplots or any loaded package) taken as a string or a function (generates colours of length breaks + 1). Pre-generated vectors of colours also permitted, creating the appropriate number of breaks.

colsep, rowsep, sepcolor

(optional) vector of integers indicating which columns or rows should be separated from the preceding columns or rows by a narrow space of color sepcolor.

sepwidth

(optional) Vector of length 2 giving the width (colsep) or height (rowsep) the separator box drawn by colsep and rowsep as a function of the width (colsep) or height (rowsep) of a cell. Defaults to c(0.05, 0.05)

cellnote

(optional) matrix of character strings which will be placed within each color cell, e.g. p-value symbols.

notecex

(optional) numeric scaling factor for cellnote items.

notecol

(optional) character string specifying the color for cellnote text. Defaults to "cyan".

na.color

Color to use for missing value (NA). Defaults to the plot background color.

trace

character string indicating whether a solid "trace" line should be drawn across 'row's or down 'column's, 'both' or 'none'. The distance of the line from the center of each color-cell is proportional to the size of the measurement. Defaults to 'column'.

tracecol

character string giving the color for "trace" line. Defaults to "cyan".

hline, vline, linecol

Vector of values within cells where a horizontal or vertical dotted line should be drawn. The color of the line is controlled by linecol. Horizontal lines are only plotted if trace is 'row' or 'both'. Vertical lines are only drawn if trace 'column' or 'both'. hline and vline default to the median of the breaks, linecol defaults to the value of tracecol.

margins

numeric vector of length 2 containing the margins (see par(mar= *)) for column and row names, respectively.

ColSideColors

(optional) character vector of length ncol(x) containing the color names for a horizontal side bar that may be used to annotate the columns of x. Enabled multiple colorbars combined with rbind: matrix where ncol(ColSideColors)=ncol(x), nrow(ColSideColors) is the number of annotation colour bars, and rownames(ColSideColors) are labels.

RowSideColors

(optional) character vector of length nrow(x) containing the color names for a vertical side bar that may be used to annotate the rows of x. Enabled multiple colorbars combined with cbind: matrix where ncol(RowSideColors)is the number of annotation colour bars, nrow(RowSideColors)=nrow(x), and colnames(RowSideColors) are labels.

cexRow, cexCol

positive numbers, used as cex.axis in for the row or column axis labeling. The defaults currently only use number of rows or columns, respectively.

labRow, labCol

character vectors with row and column labels to use; these default to rownames(x) or colnames(x), respectively.

cexLab

positive numbers, used as cex.axis in for the row or column annotation bar labeling. Relative to size of row or column labels respectively.

srtRow, srtCol

angle of row/column labels, in degrees from horizontal

adjRow, adjCol

2-element vector giving the (left-right, top-bottom) justification of row/column labels (relative to the text orientation).

offsetRow, offsetCol

Number of character-width spaces to place between row/column labels and the edge of the plotting region.

offsetLabRow, offsetLabCol

Number of character-width spaces to place between row/column axis labels and the margins.

colRow, colCol

color of row/column labels, either a scalar to set the color of all labels the same, or a vector providing the colors of each label item

key

logical indicating whether a color-key should be shown.

keysize

numeric value indicating the size of the key

density.info

character string indicating whether to superimpose a 'histogram', a 'density' plot, or no plot ('none') on the color-key.

denscol

character string giving the color for the density display specified by density.info, defaults to the same value as tracecol.

symkey

Boolean indicating whether the color key should be made symmetric about 0. Defaults to TRUE if the data includes negative values, and to FALSE otherwise.

densadj

Numeric scaling value for tuning the kernel width when a density plot is drawn on the color key. (See the adjust parameter for the density function for details.) Defaults to 0.25.

key.title

main title of the color key. If set to NA no title will be plotted.

key.xlab

x axis label of the color key. If set to NA no label will be plotted.

key.ylab

y axis label of the color key. If set to NA no label will be plotted.

key.xtickfun

function computing tick location and labels for the xaxis of the color key. Returns a named list containing parameters that can be passed to axis. See examples.

key.ytickfun

function computing tick location and labels for the y axis of the color key. Returns a named list containing parameters that can be passed to axis. See examples.

key.par

graphical parameters for the color key. Named list that can be passed to par.

main, xlab, ylab

main, x- and y-axis titles; defaults to none.

lmat, lhei, lwid

visual layout: position matrix, column height, column width. See below for details

extrafun

A function to be called after all other work. See examples.

...

additional arguments passed on to image

Value

heatmap.2 (x,

#dendrogram control Rowv = TRUE, Colv=if(symm)"Rowv" else TRUE, distfun = dist, hclustfun = hclust, dendrogram = c("both","row","column","none"), reorderfun = function(d, w) reorder(d, w), symm = FALSE,

#pass params to plot.dendrogram nodeParRow = NULL, nodeParCol = NULL, edgeParRow = NULL, edgeParCol = NULL,

#data scaling scale = c("none","row", "column"), na.rm=TRUE,

#image plot revC = identical(Colv, "Rowv"), add.expr,

#mapping data to colors breaks, symbreaks=any(x < 0, na.rm=TRUE) || scale!="none",

#colors col="heat.colors",

#block sepration colsep, rowsep, sepcolor="white", sepwidth=c(0.05,0.05),

#cell labeling cellnote, notecex=1.0, notecol="cyan", na.color=par("bg"),

#level trace trace=c("column","row","both","none"), tracecol="cyan", hline=median(breaks), vline=median(breaks), linecol=tracecol,

#Row/Column Labeling margins = c(5, 5), ColSideColors, RowSideColors, cexRow = 0.2 + 1/log10(nr), cexCol = 0.2 + 1/log10(nc), labRow = NULL, labCol = NULL, srtRow = NULL, srtCol = NULL, adjRow = c(0,NA), adjCol = c(NA,0), offsetRow = 0.5, offsetCol = 0.5, offsetLabRow = 0, offsetLabCol = 0, colRow = NULL, colCol = NULL,

#color key + density info key = TRUE, keysize = 1.5, density.info=c("histogram","density","none"), denscol=tracecol, symkey = any(x < 0, na.rm=TRUE) || symbreaks, densadj = 0.25, key.title = NULL, key.xlab = NULL, key.ylab = NULL, key.xtickfun = NULL, key.ytickfun = NULL, key.par=list(),

#plot labels main = NULL, xlab = NULL, ylab = NULL,

#plot layout lmat = NULL, lhei = NULL, lwid = NULL,

#extras extrafun=NULL, #... )

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#Generate example data
mat <- matrix(rnorm(1000), 50, 20)
#heatmap with recommended settings
heatmap.2x(mat, scale="none", trace="none", col=bluered(50))

#create color bar
colbar <- c("red", "blue")[rep(c(1,2),(ncol(mat)/2))]
heatmap.2x(mat, scale="none", trace="none", col=bluered(50), ColSideColors=colbar)
n<- 10
colbar <- rainbow(n)[rep(c(1:n),(ncol(mat)/n))]
heatmap.2x(mat, scale="none", trace="none", col=bluered(50), ColSideColors=colbar)
#These should behave just as heatmap.2

#create a row bar
rowbar <- c("red", "blue")[rep(c(1,2),(nrow(mat)/2))]
heatmap.2x(mat, scale="none", trace="none", col=bluered(50), RowSideColors=rowbar)
n<- 10
rowbar <- rainbow(n)[rep(c(1:n),(nrow(mat)/n))]
heatmap.2x(mat, scale="none", trace="none", col=bluered(50), RowSideColors=rowbar)
#These should behave just as heatmap.2

#create another color bar
colbars1 <- c("red", "blue")[rep(c(1,2),(ncol(mat)/2))]
colbars2 <- c("yellow", "green", "cyan")
colbarmat <- rbind(colbars1, colbars2)
heatmap.2x(mat, scale="none", trace="none", col=bluered(50), ColSideColors=colbarmat)

#create another color bar for rows
rowbars1 <- c("red", "blue")[rep(c(1,2),(nrow(mat)/2))]
rowbars2 <- c("yellow", "green", "cyan")
rowbarmat <- cbind(rowbars1, rowbars2)
heatmap.2x(mat, scale="none", trace="none", col=bluered(50), RowSideColors=rowbarmat)
heatmap.2x(mat, scale="none", trace="none", col=bluered(50),
           ColSideColors=colbarmat, RowSideColors=rowbarmat)

TomKellyGenetics/heatmap.2x documentation built on July 8, 2019, 4:38 a.m.