
Last chance! 50% off unlimited learning
Sale ends in
Plots a heatmap plot with color legend, row and column annotation, and optional text within th heatmap.
labeledHeatmap(
Matrix,
xLabels, yLabels = NULL,
xSymbols = NULL, ySymbols = NULL,
colorLabels = NULL,
xColorLabels = FALSE, yColorLabels = FALSE,
checkColorsValid = TRUE,
invertColors = FALSE,
setStdMargins = TRUE,
xLabelsPosition = "bottom",
xLabelsAngle = 45,
xLabelsAdj = 1,
yLabelsPosition = "left",
xColorWidth = 2 * strheight("M"),
yColorWidth = 2 * strwidth("M"),
xColorOffset = strheight("M")/3,
yColorOffset = strwidth("M")/3,
colorMatrix = NULL,
colors = NULL,
naColor = "grey",
textMatrix = NULL,
cex.text = NULL,
textAdj = c(0.5, 0.5),
cex.lab = NULL,
cex.lab.x = cex.lab,
cex.lab.y = cex.lab,
colors.lab.x = 1,
colors.lab.y = 1,
font.lab.x = 1,
font.lab.y = 1, bg.lab.x = NULL,
bg.lab.y = NULL,
x.adj.lab.y = 1,
plotLegend = TRUE,
keepLegendSpace = plotLegend,
legendLabel = "",
cex.legendLabel = 1,
# Separator line specification
verticalSeparator.x = NULL,
verticalSeparator.col = 1,
verticalSeparator.lty = 1,
verticalSeparator.lwd = 1,
verticalSeparator.ext = 0,
verticalSeparator.interval = 0,
horizontalSeparator.y = NULL,
horizontalSeparator.col = 1,
horizontalSeparator.lty = 1,
horizontalSeparator.lwd = 1,
horizontalSeparator.ext = 0,
horizontalSeparator.interval = 0,
# optional restrictions on which rows and columns to actually show
showRows = NULL,
showCols = NULL,
...)
None.
numerical matrix to be plotted in the heatmap.
labels for the columns. See Details.
labels for the rows. See Details.
additional labels used when xLabels
are interpreted as colors. See Details.
additional labels used when yLabels
are interpreted as colors. See Details.
logical: should xLabels
and yLabels
be interpreted as colors? If
given, overrides xColorLabels
and yColorLabels
below.
logical: should xLabels
be interpreted as colors?
logical: should yLabels
be interpreted as colors?
logical: should given colors be checked for validity
against the output of colors()
? If this argument is FALSE
, invalid color specification
will trigger an error.
logical: should the color order be inverted?
logical: should standard margins be set before calling the plot function?
Standard margins depend on colorLabels
: they are wider for text labels and narrower for color
labels. The defaults are static, that is the function does not attempt to guess the optimal margins.
a character string specifying the position of labels for the columns.
Recognized values are (unique abbreviations of) "top", "bottom"
.
angle by which the column labels should be rotated.
justification parameter for column labels. See par
and the
description of parameter "adj"
.
a character string specifying the position of labels for the columns.
Recognized values are (unique abbreviations of) "left", "right"
.
width of the color labels for the x axis expressed in user corrdinates.
width of the color labels for the y axis expressed in user coordinates.
gap between the y axis and color labels, in user coordinates.
gap between the x axis and color labels, in user coordinates.
optional explicit specification for the color of the heatmap cells. If given, overrides values
specified in colors
and naColor
.
color pallette to be used in the heatmap. Defaults to heat.colors
. Only used if
colorMatrix
is not given.
color to be used for encoding missing data. Only used if colorMatrix
is not used.
optional text entries for each cell. Either a matrix of the same dimensions as
Matrix
or a vector of the same length as the number of entries in Matrix
.
character expansion factor for textMatrix
.
Adjustment for the entries in the text matrix. See the adj
argument to
text
.
character expansion factor for text labels labeling the axes.
character expansion factor for text labels labeling the x axis. Overrides cex.lab
above.
character expansion factor for text labels labeling the y axis. Overrides cex.lab
above.
colors for character labels or symbols along x axis.
colors for character labels or symbols along y axis.
integer specifying font for labels or symbols along x axis. See text
.
integer specifying font for labels or symbols along y axis. See text
.
background color for the margin along the x axis.
background color for the margin along the y axs.
Justification of labels for the y axis along the x direction. A value of 0 produces left-justified text, 0.5 (the default) centered text and 1 right-justified text.
logical: should a color legend be plotted?
logical: if the color legend is not drawn, should the space be left empty
(TRUE
), or should the heatmap fill the space (FALSE
)?
character string to be shown next to the label analogous to an axis label.
character expansion factor for the legend label.
indices of columns in input Matrix
after
which separator lines (vertical lines between columns)
should be drawn. NULL
means no lines will be drawn.
color(s) of the vertical separator lines. Recycled if need be.
line type of the vertical separator lines. Recycled if need be.
line width of the vertical separator lines. Recycled if need be.
number giving the extension of the separator line into the margin as a fraction of the margin width. 0 means no extension, 1 means extend all the way through the margin.
number giving the interval for vertical separators. If larger than zero, vertical
separators will be drawn after every verticalSeparator.interval
of displayed columns.
Used only when length of verticalSeparator.x
is zero.
indices of columns in input Matrix
after which separator lines (horizontal lines
between columns) should be drawn. NULL
means no lines will be drawn.
color(s) of the horizontal separator lines. Recycled if need be.
line type of the horizontal separator lines. Recycled if need be.
line width of the horizontal separator lines. Recycled if need be.
number giving the extension of the separator line into the margin as a fraction of the margin width. 0 means no extension, 1 means extend all the way through the margin.
number giving the interval for horizontal separators. If larger than zero, horizontal
separators will be drawn after every horizontalSeparator.interval
of displayed rows.
Used only when length of horizontalSeparator.y
is zero.
A numeric vector giving the indices of rows that are actually to be shown. Defaults to all rows.
A numeric vector giving the indices of columns that are actually to be shown. Defaults to all columns.
other arguments to function heatmap
.
Peter Langfelder
The function basically plots a standard heatmap plot of the given Matrix
and embellishes it with
row and column labels and/or with text within the heatmap entries. Row and column labels can be either
character strings or color squares, or both.
To get simple text labels, use colorLabels=FALSE
and pass the desired row and column labels in
yLabels
and xLabels
, respectively.
To label rows and columns by color squares, use
colorLabels=TRUE
; yLabels
and xLabels
are then expected to represent valid colors.
For reasons of compatibility with other functions, each entry in yLabels
and xLabels
is
expected to consist of a color designation preceded by 2 characters: an example would be
MEturquoise
. The first two characters can be arbitrary, they are stripped.
Any labels that do not represent valid colors will be considered text labels and printed in full,
allowing the user to mix text and color labels.
It is also possible to label rows and columns by both color squares and additional text annotation. To
achieve this, use the above technique to get color labels and, additionally, pass the desired text
annotation in the xSymbols
and ySymbols
arguments.
# This example illustrates 4 main ways of annotating columns and rows of a heatmap.
# Copy and paste the whole example into an R session with an interactive plot window;
# alternatively, you may replace the command sizeGrWindow below by opening
# another graphical device such as pdf.
# Generate a matrix to be plotted
nCol = 8; nRow = 7;
mat = matrix(runif(nCol*nRow, min = -1, max = 1), nRow, nCol);
rowColors = standardColors(nRow);
colColors = standardColors(nRow + nCol)[(nRow+1):(nRow + nCol)];
rowColors;
colColors;
sizeGrWindow(9,7)
par(mfrow = c(2,2))
par(mar = c(4, 5, 4, 6));
# Label rows and columns by text:
labeledHeatmap(mat, xLabels = colColors, yLabels = rowColors,
colors = greenWhiteRed(50),
setStdMargins = FALSE,
textMatrix = signif(mat, 2),
main = "Text-labeled heatmap");
# Label rows and columns by colors:
rowLabels = paste("ME", rowColors, sep="");
colLabels = paste("ME", colColors, sep="");
labeledHeatmap(mat, xLabels = colLabels, yLabels = rowLabels,
colorLabels = TRUE,
colors = greenWhiteRed(50),
setStdMargins = FALSE,
textMatrix = signif(mat, 2),
main = "Color-labeled heatmap");
# Mix text and color labels:
rowLabels[3] = "Row 3";
colLabels[1] = "Column 1";
labeledHeatmap(mat, xLabels = colLabels, yLabels = rowLabels,
colorLabels = TRUE,
colors = greenWhiteRed(50),
setStdMargins = FALSE,
textMatrix = signif(mat, 2),
main = "Mix-labeled heatmap");
# Color labels and additional text labels
rowLabels = paste("ME", rowColors, sep="");
colLabels = paste("ME", colColors, sep="");
extraRowLabels = paste("Row", c(1:nRow));
extraColLabels = paste("Column", c(1:nCol));
# Extend margins to fit all labels
par(mar = c(6, 6, 4, 6));
labeledHeatmap(mat, xLabels = colLabels, yLabels = rowLabels,
xSymbols = extraColLabels,
ySymbols = extraRowLabels,
colorLabels = TRUE,
colors = greenWhiteRed(50),
setStdMargins = FALSE,
textMatrix = signif(mat, 2),
main = "Text- + color-labeled heatmap");
Run the code above in your browser using DataLab