heatmap.2
heatmap.2 {gplots} | R Documentation |
Enhanced Heat Map
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","row","column","none"),
symm = FALSE, # data scaling
scale = c("none","row", "column"),
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","row","both","none"),
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,
srtRow = NULL,
srtCol = NULL,
adjRow = c(0,NA),
adjCol = c(NA,0),
offsetRow = 0.5,
offsetCol = 0.5, # color key + density info
key = TRUE,
keysize = 1.5,
density.info=c("histogram","density","none"),
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 |
numeric matrix of the values to be plotted. |
Rowv |
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 |
Colv |
determines if and how the column dendrogram should be reordered. Has the options as the |
distfun |
function used to compute the distance (dissimilarity) between both rows and columns. Defaults to |
hclustfun |
function used to compute the hierarchical clustering when |
dendrogram |
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. |
symm |
logical indicating if |
scale |
character indicating if the values should be centered and scaled in either the row direction or the column direction, or none. The default is |
na.rm |
logical indicating whether |
revC |
logical indicating if the column order should be |
add.expr |
expression that will be evaluated after the call to |
breaks |
(optional) Either a numeric vector indicating the splitting points for binning |
symbreaks |
Boolean indicating whether breaks should be made symmetric about 0. Defaults to |
col |
colors used for the image. Defaults to heat colors ( |
colsep, rowsep, sepcolor |
(optional) vector of integers indicating which columns or rows should be separated from the preceding columns or rows by a narrow space of color |
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 |
cellnote |
(optional) matrix of character strings which will be placed within each color cell, e.g. p-value symbols. |
notecex |
(optional) numeric scaling factor for |
notecol |
(optional) character string specifying the color for |
na.color |
Color to use for missing value ( |
trace |
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'. |
tracecol |
character string giving the color for "trace" line. Defaults to "cyan". |
hline, vline, linecol |
Vector of values within cells where a horizontal or vertical dotted line should be drawn. The color of the line is controlled by |
margins |
numeric vector of length 2 containing the margins (see |
ColSideColors |
(optional) character vector of length |
RowSideColors |
(optional) character vector of length |
cexRow, cexCol |
positive numbers, used as |
labRow, labCol |
character vectors with row and column labels to use; these default to |
srtRow, srtCol |
angle of row/column labels, in degrees from horizontal |
adjRow, adjCol |
2-element vector giving the (left-right, top-bottom) justification of row/column labels (relative to the text orientation). |
offsetRow, offsetCol |
Number of character-width spaces to place between row/column labels and the edge of the plotting region. |
key |
logical indicating whether a color-key should be shown. |
keysize |
numeric value indicating the size of the key |
density.info |
character string indicating whether to superimpose a 'histogram', a 'density' plot, or no plot ('none') on the color-key. |
denscol |
character string giving the color for the density display specified by |
symkey |
Boolean indicating whether the color key should be made symmetric about 0. Defaults to |
densadj |
Numeric scaling value for tuning the kernel width when a density plot is drawn on the color key. (See the |
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 |
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 X
is 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,
, in the row case.
Rowv)
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 |
row index permutation vector as returned by |
colInd |
column index permutation vector. |
call |
the matched call |
rowMeans, rowSDs |
mean and standard deviation of each row: only |
colMeans, colSDs |
mean and standard deviation of each column: only |
carpet |
reordered and scaled 'x' values used generate the main |
rowDendrogram |
row dendrogram, if present |
colDendrogram |
column dendrogram, if present |
breaks |
values used for color break points |
col |
colors used |
vline |
center-line value used for column trace, present only if |
hline |
center-line value used for row trace, present only if |
colorTable |
A three-column data frame providing the lower and upper |
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., when par(mfrow= *)
or (mfcol= *)
has been called.
Author(s)
Andy Liaw, original; R. Gentleman, M. Maechler, W. Huber,
G. Warnes, revisions.
See Also
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 row and column label rotation
heatmap.2(x, srtCol=NULL)
heatmap.2(x, srtCol=0, adjCol = c(0.5,1) )
heatmap.2(x, srtCol=45, adjCol = c(1,1) )
heatmap.2(x, srtCol=135, adjCol = c(1,0) )
heatmap.2(x, srtCol=180, adjCol = c(0.5,0) )
heatmap.2(x, srtCol=225, adjCol = c(0,0) ) ## not very useful
heatmap.2(x, srtCol=270, adjCol = c(0,0.5) )
heatmap.2(x, srtCol=315, adjCol = c(0,1) )
heatmap.2(x, srtCol=360, adjCol = c(0.5,1) ) heatmap.2(x, srtRow=45, adjRow=c(0, 1) )
heatmap.2(x, srtRow=45, adjRow=c(0, 1), srtCol=45, adjCol=c(1,1) )
heatmap.2(x, srtRow=45, adjRow=c(0, 1), srtCol=270, adjCol=c(0,0.5) ) ## Show effect of offsetRow/offsetCol (only works when srtRow/srtCol is
## not also present)
heatmap.2(x, offsetRow=0, offsetCol=0)
heatmap.2(x, offsetRow=1, offsetCol=1)
heatmap.2(x, offsetRow=2, offsetCol=2)
heatmap.2(x, offsetRow=-1, offsetCol=-1) heatmap.2(x, srtRow=0, srtCol=90, offsetRow=0, offsetCol=0)
heatmap.2(x, srtRow=0, srtCol=90, offsetRow=1, offsetCol=1)
heatmap.2(x, srtRow=0, srtCol=90, offsetRow=2, offsetCol=2)
heatmap.2(x, srtRow=0, srtCol=90, offsetRow=-1, offsetCol=-1) ##
## Show effect of z-score scaling within columns, blue-red color scale
##
hv <- heatmap.2(x, col=bluered, scale="column", tracecol="#303030") ###
## 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",1:2])
rbind(whiteBin[1] * hv$colSDs + hv$colMeans,
whiteBin[2] * hv$colSDs + hv$colMeans )
##
## A more decorative heatmap, with z-score scaling along columns
##
hv <- heatmap.2(x, col=cm.colors(255), scale="column",
RowSideColors=rc, ColSideColors=cc, margin=c(5, 10),
xlab="specification variables", ylab= "Car Models",
main="heatmap(<Mtcars data>, ..., scale=\"column\")",
tracecol="green", density="density")
## 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", ylab="Probeset",
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", ylab="Probeset") ## End(Not run)
heatmap.2的更多相关文章
- 基于HTML5实现3D热图Heatmap应用
Heatmap热图通过众多数据点信息,汇聚成直观可视化颜色效果,热图已广泛被应用于气象预报.医疗成像.机房温度监控等行业,甚至应用于竞技体育领域的数据分析. http://www.hightopo.c ...
- 【JS】heatmap.js v1.0 到 v2.0,详细总结一下:)
前段时间,项目要开发热力图插件,研究了heatmap.js,打算好好总结一下. 本文主要有以下几部分内容: 部分源码理解 如何迁移到v2.0 v2.0官方文档译文 关于heatmap.js介绍,请看这 ...
- funsioncharts的图表操作heatmap
网址:http://www.fusioncharts.com/dev/chart-guide/heat-map-chart/introduction.html 以下只是假数据,目前还没有实现动态数据获 ...
- 用Excel制作热图(heatmap)的方法
http://jingyan.baidu.com/article/64d05a0240ec75de55f73bd8.html 利用Excel 2010及以上版本的"条件格式"--& ...
- Heatmap.js v2.0 – 最强大的 Web 动态热图
Heatmap 是用来呈现一定区域内的统计度量,最常见的网站访问热力图就是以特殊高亮的形式显示访客热衷的页面区域和访客所在的地理区域的图示.Heatmap.js 这个 JavaScript 库可以实现 ...
- R实战之热点图(HeatMap)
快速实现是搜索帮助文档的首要目的,所以此处涉及实战的文章一概略去传统帮助文档的理论部分,直接上代码加注释! 本文将介绍R语言下利用ggplot2包制作heatmap的代码 -------------- ...
- 基于HTML5实现的Heatmap热图3D应用
Heatmap热图通过众多数据点信息,汇聚成直观可视化颜色效果,热图已广泛被应用于气象预报.医疗成像.机房温度监控等行业,甚至应用于竞技体育领域的数据分析. 已有众多文章分享了生成Heatmap热图原 ...
- 网页热力图 heatmap js
HBuilder +js 实现网页热力图 废话不多说,上代码 <!DOCTYPE html> <html> <head> <title>111</ ...
- Leaflet+heatmap实现离线地图加载和热力图应用
本人博客主页:http://www.cnblogs.com/webbest/ 2017年春节已经过完,新一年的奋斗也刚刚开始.今年要经历的挑战也是大大的...不扯了. 年底前软件项目相对较多,恰巧在年 ...
随机推荐
- JGibbLDA:java版本的LDA(Latent Dirichlet Allocation)实现、修改及使用
转载自:http://blog.csdn.net/memray/article/details/16810763 一.概述 JGibbLDA是一个java版本的LDA(Latent Dirichl ...
- 针对谷歌默认最小字体12px的正确解决方案 (css、html)
今天晨会,产品要求把以前12px的字体改小一点,我心想这有什么难的,就随口答应了.哪知,改css的时候,谷歌浏览器中font-size小于12px时,字体就不会再缩小了.当时我的第一反应就是会不会是其 ...
- 【BZOJ】【1022】【SHOI2008】小约翰的游戏John
博弈论 一看题,哇这不是Nim游戏么= =直接异或起来……啊咧怎么不对? 这道题是[Anti-Nim],普通的Nim是取走最后一个就赢,这题是取走最后一个输…… 做法参见 2009年贾志豪论文< ...
- 2012 Asia JinHua Regional Contest
Draw Something http://acm.hdu.edu.cn/showproblem.php?pid=4450 o(n)统计输入每个数的平方和. #include<cstdio> ...
- asynDBCenter(修改)
asynDBCenter加入数据库心跳,其实是没有找到更好的方法,看看和以前有什么不同 mongo数据库重练,暂时没有找到好办法,只能这样定时访问 bool asynDBCenter::init(bo ...
- [设计模式] 17 中介者模式 Mediator Pattern
在GOF的<设计模式:可复用面向对象软件的基础>一书中对中介者模式是这样说的:用一个中介对象来封装一系列的对象交互.中介者使各对象不需要显式地相互引用,从而使其耦合松散,而且可以独立地改变 ...
- 基于HOOK和MMF的Windows密码渗透技术
随着计算机与网络的普及,信息安全越来越成为人们所普遍关心的大事.密码的渗透与反渗透在此领域表现的愈演愈烈.本文深入分析了各个版本Windows密码的特点,尤其是针对windws2K/XP安全性提高的情 ...
- 谁会是 Zabbix 和 Nagios 的继任者?
[编者按]本文根据 Dataloop.IO 的创始人兼 CEO David Gildeh 对监控工具市场的现状分析以及对未来发展趋势的展望,展开拓展讨论. 为什么监控还是一塌糊涂? 为了调研市场,从而 ...
- Appboy 基于 MongoDB 的数据密集型实践
摘要:Appboy 正在过手机等新兴渠道尝试一种新的方法,让机构可以与顾客建立更好的关系,可以说是市场自动化产业的一个前沿探索者.在移动端探索上,该公司已经取得了一定的成功,知名产品有 iHeartM ...
- mac上eclipse上运行word count
1.打开eclipse之后,建立wordcount项目 package wordcount; import java.io.IOException; import java.util.StringTo ...