labeledHeatmap: Produce a labeled heatmap plot

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Plots a heatmap plot with color legend, row and column annotation, and optional text within th heatmap.

Usage

 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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,
  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,

  # Separator line specification                   
  verticalSeparator.x = NULL,
  verticalSeparator.col = 1,
  verticalSeparator.lty = 1,
  verticalSeparator.lwd = 1,
  verticalSeparator.ext = 0,

  horizontalSeparator.y = NULL,
  horizontalSeparator.col = 1,
  horizontalSeparator.lty = 1,
  horizontalSeparator.lwd = 1,
  horizontalSeparator.ext = 0,
  ...)

Arguments

Matrix

numerical matrix to be plotted in the heatmap.

xLabels

labels for the columns. See Details.

yLabels

labels for the rows. See Details.

xSymbols

additional labels used when xLabels are interpreted as colors. See Details.

ySymbols

additional labels used when yLabels are interpreted as colors. See Details.

colorLabels

logical: should xLabels and yLabels be interpreted as colors? If given, overrides xColorLabels and yColorLabels below.

xColorLabels

logical: should xLabels be interpreted as colors?

yColorLabels

logical: should yLabels be interpreted as colors?

checkColorsValid

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.

invertColors

logical: should the color order be inverted?

setStdMargins

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.

xLabelsPosition

a character string specifying the position of labels for the columns. Recognized values are (unique abbreviations of) "top", "bottom".

xLabelsAngle

angle by which the column labels should be rotated.

xLabelsAdj

justification parameter for column labels. See par and the description of parameter "adj".

yLabelsPosition

a character string specifying the position of labels for the columns. Recognized values are (unique abbreviations of) "left", "right".

xColorWidth

width of the color labels for the x axis expressed in user corrdinates.

yColorWidth

width of the color labels for the y axis expressed in user coordinates.

xColorOffset

gap between the y axis and color labels, in user coordinates.

yColorOffset

gap between the x axis and color labels, in user coordinates.

colors

color pallette to be used in the heatmap. Defaults to heat.colors.

naColor

color to be used for encoding missing data.

textMatrix

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.

cex.text

character expansion factor for textMatrix.

textAdj

Adjustment for the entries in the text matrix. See the adj argument to text.

cex.lab

character expansion factor for text labels labeling the axes.

cex.lab.x

character expansion factor for text labels labeling the x axis. Overrides cex.lab above.

cex.lab.y

character expansion factor for text labels labeling the y axis. Overrides cex.lab above.

colors.lab.x

colors for character labels or symbols along x axis.

colors.lab.y

colors for character labels or symbols along y axis.

font.lab.x

integer specifying font for labels or symbols along x axis. See text.

font.lab.y

integer specifying font for labels or symbols along y axis. See text.

bg.lab.x

background color for the margin along the x axis.

bg.lab.y

background color for the margin along the y axs.

x.adj.lab.y

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.

plotLegend

logical: should a color legend be plotted?

keepLegendSpace

logical: if the color legend is not drawn, should the space be left empty (TRUE), or should the heatmap fill the space (FALSE)?

verticalSeparator.x

indices of columns after which separator lines (vertical lines between columns) should be drawn. NULL means no lines will be drawn.

verticalSeparator.col

color(s) of the vertical separator lines. Recycled if need be.

verticalSeparator.lty

line type of the vertical separator lines. Recycled if need be.

verticalSeparator.lwd

line width of the vertical separator lines. Recycled if need be.

verticalSeparator.ext

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.

horizontalSeparator.y

indices of columns after which separator lines (horizontal lines between columns) should be drawn. NULL means no lines will be drawn.

horizontalSeparator.col

color(s) of the horizontal separator lines. Recycled if need be.

horizontalSeparator.lty

line type of the horizontal separator lines. Recycled if need be.

horizontalSeparator.lwd

line width of the horizontal separator lines. Recycled if need be.

horizontalSeparator.ext

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.

...

other arguments to function heatmap.

Details

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.

Value

None.

Author(s)

Peter Langfelder

See Also

heatmap, colors

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# 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");

nosarcasm/WGCNA documentation built on May 28, 2019, 1:01 p.m.