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 function. Usage
heatmap.2 (x,
# dendrogram control Rowv = TRUE,
Colv=if(symm)\"Rowv\" else TRUE, distfun = dist, hclustfun = hclust,
dendrogram = c(\"both\ symm = FALSE,
# data scaling
scale = c(\"none\ na.rm=TRUE,
# image plot
revC = identical(Colv, \"Rowv\"), add.expr,
# mapping data to colors breaks,
symbreaks=min(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\ 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,
# color key + density info key = TRUE, keysize = 1.5,
density.info=c(\"histogram\ denscol=tracecol,
symkey = min(x < 0, na.rm=TRUE) || symbreaks, densadj = 0.25,
# plot labels main = NULL, xlab = NULL, ylab = NULL,
# plot layout lmat = NULL, lhei = NULL, lwid = NULL,
# extras
... )
Arguments
x Rowv
Colv
distfun hclustfun dendrogram
symm scale
na.rm revC
add.expr breaks
numeric matrix of the values to be plotted.
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, then it is used \"as-is\vector of integers, then dendrogram is computed and reordered based on the order of the vector.
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.
function used to compute the distance (dissimilarity) between both rows and columns. Defaults to dist. function used to compute the hierarchical clustering
when Rowv or Colv are not dendrograms. Defaults to hclust. 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.
logical indicating if x should be treated symmetrically; can only be true when x is a square matrix.
character indicating if the values should be centered and scaled in either the row direction or the column direction, or none. The default is \"row\"if symm false, and \"none\" otherwise. logical indicating whether NA's should be removed.
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.
expression that will be evaluated after the call to image. Can be used to add components to the plot.
(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.
colors used for the image. Defaults to heat colors (heat.colors).
col
colsep, rowsep, (optional) vector of integers indicating which columns or rows sepcolor should be separated from the preceding columns or rows by a
narrow space of colorsepcolor. 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)
(optional) matrix of character strings which will be placed within each color cell, e.g. p-value symbols.
(optional) numeric scaling factor for cellnote items.
(optional) character string specifying the color for cellnote text. Defaults to \"green\".
Color to use for missing value (NA). Defaults to the plot background color.
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'.
character string giving the color for \"trace\" line. Defaults to \"cyan\". 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.
numeric vector of length 2 containing the margins (see par(mar= *)) for column and row names, respectively.
cellnote notecex notecol na.color trace
tracecol hline, vline, linecol
margins
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. 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. 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.
key keysize density.info denscol symkey
logical indicating whether a color-key should be shown. numeric value indicating the size of the key
character string indicating whether to superimpose a 'histogram', a 'density' plot, or no plot ('none') on the color-key.
character string giving the color for the density display specified by density.info, defaults to the same value as tracecol.
Boolean indicating whether the color key should be made symmetric about 0. Defaults to TRUE if the data includes negative values, and to FALSEotherwise.
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.
densadj
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 ...
additional arguments passed on to image Details
If either Rowv or Colv are dendrograms they are honored (and not reordered). Otherwise, dendrograms are computed as dd <-
as.dendrogram(hclustfun(distfun(X))) where Xis either x or t(x).
If either is a vector (of “weights”) then the appropriate dendrogram is reordered according to the supplied values subject to the constraints imposed by the dendrogram, by reorder(dd, Rowv), in the row case. If either is missing, as by default, then the ordering of the corresponding dendrogram is by the mean value of the rows/columns, i.e., in the case of rows, Rowv <- rowMeans(x, na.rm=na.rm). If either is NULL, no reordering will be done for the corresponding side.
If scale=\"row\" the rows are scaled to have mean zero and standard deviation one. There is some empirical evidence from genomic plotting that this is useful.
The default colors range from red to white (heat.colors) and are not pretty. Consider using enhancements such as the RColorBrewer package, http://cran.r-project.org/src/contrib/PACKAGES.html#RColorBrewer to select better colors. By default four components will be displayed in the plot. At the top left is the color key, top right is the column dendogram, bottom left is the row dendogram, bottom right is the image plot. When RowSideColor or
ColSideColor are provided, an additional row or column is inserted in the appropriate location. This layout can be overriden by specifiying appropriate values for lmat, lwid, and lhei. lmat controls the relative postition of each element, while lwid controls the column width, and lhei controls the row height. See the help page for layout for details on how to use these arguments.
Value
Invisibly, a list with components
rowInd colInd call rowMeans, rowSDs
row index permutation vector as returned by order.dendrogram. column index permutation vector. the matched call
mean and standard deviation of each row: only present if scale=\"row\"
colMeans, colSDs mean and standard deviation of each column: only present
if scale=\"column\" carpet colDendrogram breaks col vline hline colorTable
reordered and scaled 'x' values used generate the main 'carpet' column dendrogram, if present values used for color break points colors used
center-line value used for column trace, present only if trace=\"both\" or trace=\"column\"
center-line value used for row trace, present only if trace=\"both\" or trace=\"row\"
A three-column data frame providing the lower and upper bound and color for each bin
rowDendrogram row dendrogram, if present
Note
The original rows and columns are reordered in any case to match the dendrogram, e.g., the rows by order.dendrogram(Rowv) where Rowv is the (possibly reorder()ed) row dendrogram. heatmap.2() uses layout and draws the image in the lower right corner of a 2x2 layout. Consequentially, it can not be used in a multi column/row layout, i.e., whenpar(mfrow= *) or (mfcol= *) has been called.
Author(s)
Andy Liaw, original; R. Gentleman, M. Maechler, W. Huber, G. Warnes, revisions.
See Also
image, hclust Examples
library(gplots) data(mtcars)
x <- as.matrix(mtcars)
rc <- rainbow(nrow(x), start=0, end=.3) cc <- rainbow(ncol(x), start=0, end=.3) ##
## demonstrate the effect of row and column dendogram options ##
heatmap.2(x) ## default - dendrogram plotted and reordering done.
heatmap.2(x, dendrogram=\"none\") ## no dendrogram plotted, but reordering done.
heatmap.2(x, dendrogram=\"row\") ## row dendrogram plotted and row reordering done.
heatmap.2(x, dendrogram=\"col\") ## col dendrogram plotted and col reordering done.
heatmap.2(x, keysize=2) ## default - dendrogram plotted and reordering done.
heatmap.2(x, Rowv=FALSE, dendrogram=\"both\") ## generate warning!
heatmap.2(x, Rowv=NULL, dendrogram=\"both\") ## generate warning! heatmap.2(x, Colv=FALSE, dendrogram=\"both\") ## generate warning! ##
## Show effect of z-score scaling within columns, blue-red color scale ##
hv <- heatmap.2(x, col=bluered, scale=\"column\
###
## Look at the return values ###
names(hv)
## Show the mapping of z-score values to color bins hv$colorTable
## Extract the range associated with white 提取与白色相关联的范围
hv$colorTable[hv$colorTable[,\"color\"]==\"#FFFFFF\
## Determine the original data values that map to white 确定原始数据值映射到白色
whiteBin <- unlist(hv$colorTable[hv$colorTable[,\"color\"]==\"#FFFFFF\ rbind(whiteBin[1] * hv$colSDs + hv$colMeans, whiteBin[2] * hv$colSDs + hv$colMeans ) ##
## A more decorative heatmap, with z-score scaling along columns ##装饰的热图,与z值
hv <- heatmap.2(x, col=cm.colors(255), scale=\"column\ RowSideColors=rc, ColSideColors=cc, margin=c(5, 10), xlab=\"specification variables\ main=\"heatmap( ## Note that the breakpoints are now symmetric about 0 data(attitude) round(Ca <- cor(attitude), 2) symnum(Ca) # simple graphic # with reorder heatmap.2(Ca, symm=TRUE, margin=c(6, 6), trace=\"none\" ) # without reorder heatmap.2(Ca, Rowv=FALSE, symm=TRUE, margin=c(6, 6), trace=\"none\" ) ## Place the color key below the image plot heatmap.2(x, lmat=rbind( c(0, 3), c(2,1), c(0,4) ), lhei=c(1.5, 4, 2 ) ) ## Place the color key to the top right of the image plot heatmap.2(x, lmat=rbind( c(0, 3, 4), c(2,1,0 ) ), lwid=c(1.5, 4, 2 ) ) ## For variable clustering, rather use distance based on cor(): data(USJudgeRatings) symnum( cU <- cor(USJudgeRatings) ) hU <- heatmap.2(cU, Rowv=FALSE, symm=TRUE, col=topo.colors(16), distfun=function(c) as.dist(1 - c), trace=\"none\") ## The Correlation matrix with same reordering: hM <- format(round(cU, 2)) hM # now with the correlation matrix on the plot itself heatmap.2(cU, Rowv=FALSE, symm=TRUE, col=rev(heat.colors(16)), distfun=function(c) as.dist(1 - c), trace=\"none\ cellnote=hM) ## genechip data examples ## Not run: library(affy) data(SpikeIn) pms <- SpikeIn@pm # just the data, scaled across rows heatmap.2(pms, col=rev(heat.colors(16)), main=\"SpikeIn@pm\ xlab=\"Relative Concentration\ scale=\"row\") # fold change vs \"12.50\" sample data <- pms / pms[, \"12.50\"] data <- ifelse(data>1, data, -1/data) heatmap.2(data, breaks=16, col=redgreen, tracecol=\"blue\ main=\"SpikeIn@pm Fold Changes\\nrelative to 12.50 sample\ xlab=\"Relative Concentration\ ## End(Not run) 因篇幅问题不能全部显示,请点此查看更多更全内容