pheatmap (version 0.2)

pheatmap: Pretty heatmaps


A function to draw clustered heatmaps.


pheatmap(mat, color = colorRampPalette(rev(c("#D73027", "#FC8D59", "#FEE090",
	 "#FFFFBF", "#E0F3F8", "#91BFDB", "#4575B4")))(100), breaks = NA, 
	cellwidth = NA, cellheight = NA, scale = "none", cluster_rows = TRUE,
	 cluster_cols = TRUE, clustering_distance = "correlation",
	 clustering_method = "complete", treeheight_row = ifelse(cluster_rows, 50, 0),
	 treeheight_col = ifelse(cluster_cols, 50, 0), legend = TRUE, annotation = NA,
	 annotation_colors = NA, annotation_legend = TRUE, filename = NA, width = NA, 
	height = NA, ...)


numeric matrix of the values to be plotted.
vector of colors used in heatmap.
a sequence of numbers that covers the range of values in mat and is one element longer than color vector. Used for mapping values to colors. Useful, if needed to map certain values to certain colors, to certain values. If value is NA then the breaks are c
cellwidth, cellheight
Individual cell measurements in points. If left as NA, then the values depend on the size of plotting window.
character indicating if the values should be centered and scaled in either the row direction or the column direction, or none. Corresponding values are "row", "column" and "none"
distance measure used in clustering. Possible values are "correlation" and all the distances supported by dist, such as "euclidean", etc.
clustering method used. Accepts the same values as hclust.
cluster_rows, cluster_cols
boolean values determining if either rows or columns should be clustered.
treeheight_row, treeheight_col
the height of a tree, if data is clustered, default value 50 points.
boolean value that determines if legend should be drawn or not.
data frame that specifies the annotations shown on top of the columns. Each row defines the features for a specific column. The columns in the data and rows in the annotation are matched using corresponding row and column names. Note that color schemes ta
list for specifying annotation track colors manually. It is possible to define the colors for only some of the features. Check examples for details.
boolean value showing if the legend for annotation tracks should be drawn.
file path ending with .pdf where to save the picture. Even if the plot does not fit into the plotting window, the file size is calculated so that the plot would fit there, unless specified otherwise.
width, height
manual options for determining the output file measurements in inches.
graphical parameters for the text used in plot. Parameters passed to grid.text, see gpar. For text size use parameter fontsize (default = 10).


Run this code
# Generate some data
	test = matrix(rnorm(200), 20, 10)
	test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
	test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
	colnames(test) = paste("Test", 1:10, sep = "")
	rownames(test) = paste("Gene", 1:20, sep = "")

	# Draw heatmaps
	pheatmap(test, scale = "row", clustering_distance = "correlation")
	pheatmap(test, color = colorRampPalette(c("navy", "white", "firebrick3"))(50))
	pheatmap(test, cluster_row = FALSE)
	pheatmap(test, legend = FALSE)
	pheatmap(test, cellwidth = 15, cellheight = 12)
	pheatmap(test, cellwidth = 15, cellheight = 12, fontsize = 8, filename = "test.pdf")

	# Generate column annotations
	annotation = data.frame(Var1 = factor(1:10 %% 2 == 0, labels = c("Class1", "Class2"))
	, Var2 = 1:10)
	rownames(annotation) = paste("Test", 1:10, sep = "")

	pheatmap(test, annotation = annotation)
	pheatmap(test, annotation = annotation, annotation_legend = FALSE)

	# Specify colors
	Var1 = c("navy", "darkgreen")
	names(Var1) = c("Class1", "Class2")
	Var2 = c("lightgreen", "navy")

	ann_colors = list(Var1 = Var1, Var2 = Var2)

	pheatmap(test, annotation = annotation, annotation_colors = ann_colors)

Run the code above in your browser using DataCamp Workspace