This function draws a heatmap from a matrix, similarly to image
. It also offers normalization and annotation features, with more control than heatmap
.
side
can provide multiple sample annotations, and are handled differently depending on their class :
are attributed grey shades from the minimum to the maximum, which are provided in the legend
have their levels attributed colors using a default or custom palette. Hexadecimal color codes starting with #
and color names known by R are used "as is".
are printed as is in a blank cell. Hexadecimal color codes starting with #
and color names known by R are used as background colors instead of text.
are ploted in dark (TRUE) or light (FALSE) gray, leaving NAs in white.
heat.map(expr, side = NULL, cex.col = NA, cex.row = NA, mai.left = NA,
mai.bottom = NA, mai.right = 0.1, mai.top = 0.1, side.height = 1, side.col = NULL,
side.srt = 0, side.cex = 1, col.heatmap = heat(), zlim = "0 centered",
zlim.trim = 0.02, norm = c("rows", "columns", "none"), norm.robust = FALSE,
customLayout = FALSE, getLayout = FALSE, font = c(1, 3), xaxt = "s", yaxt = "s")
A numeric matrix, holding features (genes) in columns and observations (samples) in rows. Column and row order will not be altered.
An annotation data.frame
for expr
, or NULL
. Must contain at least a row for each expr
row, and one or many annotation column. Merging is performed on row names, so rows must be named following the same conventions as expr
. Hexadecimal color definitions will be used "as is", other values will be attributed colors according to side.col
.
Single numeric value, character exapansion factor for column names. NA
will compute a value from expr
size, similarly to heatmap
.
Single numeric value, character exapansion factor for row names. NA
will compute a value from expr
size, similarly to heatmap
.
Single numeric value, left margin in inches (for row names). Use NA
for an automatic value computed from row name lengths. See par
.
Single numeric value, bottom margin in inches (for column names). Use NA
for an automatic value computed from column name lengths. See par
.
Single numeric value, right margin in inches (for higher level functions). See par
.
Single numeric value, top margin in inches. See par
.
Single numeric value, scaling factor for annotation track.
A function returning as many colors as requested by its sole argument, defining the colors to be used for side
legend. Default uses a custom palette for few values, and a derivative of rainbow
if more than 8 colors are needed.
Single numeric value, determining the string rotation angle when writing character side columns (default is 0, horizontal, 90 is suggested for vertical text on busy heat maps).
Single numeric value, the character expansion factor to use for character side columns.
Character vector of colors, to be used for the cells of the heat map.
Numeric vector of length two, defining minimal and maximal expr
values that will be mapped to colors in col.heatmap
. Values outside of this range will be rounded to the mearest boundary. Two special values are also allowed : "0 centered" to get a symetrical range around 0 (with the default palette, it enforces 0 as the center color), and "range" to get expr
range after normalization.
Single numeric value between 0 and 1, defining the proportion of extreme values (equally split on both sides) to remove before computing "0 centered" or "range" zlim
.
Single character value, normalization to be performed (use "none" to perform no normalization). "rows" will center and scale genes, while "columns" will center and scale samples. The functions used depend on norm.robust
.
Single logical value, as layout
does not allow nested calls, set this to TRUE to make your own call to layout and embed this plot in a wider one. See also getLayout
.
Single logical value, whether to only return the layout
arguments that would be used with the set of arguments provided or not. It can prove useful to build custom layouts, e.g. merging this plot to an other. See also customLayout
.
Integer vector of length two, the font
used to draw X and Y axis labels respectively (see par
). Default is to print X labels (usually samples) in normal font and Y labels (usually genes) in italic font.
Single letter, whether to print column labels ("s") or not ("n").
Single letter, whether to print row labels ("s") or not ("n").
Invisibly returns a named list :
Final value of the zlim
argument.
Final value of the col.heatmap
argument.
If side
is used, a named character vector of colors used for annotation.
Final value of the cex.col
argument.
Final value of the cex.row
argument.
Final value of the mai.left
argument.
Final value of the mai.bottom
argument.
# NOT RUN {
# Data with features in columns
data(rosenwald)
group <- rosenwald.cli$group
expr <- t(rosenwald.expr)[,1:100]
# NA imputation (feature's mean to minimize impact)
f <- function(x) { x[ is.na(x) ] <- round(mean(x, na.rm=TRUE), 3); x }
expr <- apply(expr, 2, f)
# Simple heat map
heat.map(expr)
# With annotation (row named data.frame)
side <- data.frame(group, row.names=rownames(expr))
heat.map(expr, side=side)
# }
Run the code above in your browser using DataLab