注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

云之南

风声,雨声,读书声,声声入耳;家事,国事,天下事,事事关心

 
 
 

日志

 
 
关于我

专业背景:计算机科学 研究方向与兴趣: JavaEE-Web软件开发, 生物信息学, 数据挖掘与机器学习, 智能信息系统 目前工作: 基因组, 转录组, NGS高通量数据分析, 生物数据挖掘, 植物系统发育和比较进化基因组学

网易考拉推荐

draw clustered heatmaps_pheatmap(热图)  

2013-10-16 15:47:48|  分类: R&Bioconductor |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
http://rgm3.lab.nig.ac.jp/RGM/R_rdfile?f=pheatmap/man/pheatmap.Rd&d=R_CC
http://cran.r-project.org/web/packages/pheatmap/index.html
http://www.blogbus.com/frewise-logs/181403065.html 用R画heatmap图
http://pgfe.umassmed.edu/ou/archives/2477 R绘图基础(四)热图 heatmap
 

Last data update: 2013.05.20

Data Source

R Release (2.15.3)
CranContrib
BioConductor
All

Data Type

Packages
Functions
Images
Data set
pheatmapR Documentation

A function to draw clustered heatmaps.

Description

A function to draw clustered heatmaps where one has better control over some graphical parameters such as cell size, etc.

Usage

  pheatmap(mat,
    color = colorRampPalette(rev(c("#D73027", "#FC8D59", "#FEE090", "#FFFFBF", "#E0F3F8", "#91BFDB", "#4575B4")))(100),
    kmeans_k = NA, breaks = NA, border_color = "grey60",
    cellwidth = NA, cellheight = NA, scale = "none",
    cluster_rows = TRUE, cluster_cols = TRUE,
    clustering_distance_rows = "euclidean",
    clustering_distance_cols = "euclidean",
    clustering_method = "complete",
    treeheight_row = ifelse(cluster_rows, 50, 0),
    treeheight_col = ifelse(cluster_cols, 50, 0),
    legend = TRUE, legend_breaks = NA, legend_labels = NA,
    annotation = NA, annotation_colors = NA,
    annotation_legend = TRUE, drop_levels = TRUE,
    show_rownames = T, show_colnames = T, main = NA,
    fontsize = 10, fontsize_row = fontsize,
    fontsize_col = fontsize, display_numbers = F,
    number_format = "%.2f",
    fontsize_number = 0.8 * fontsize, filename = NA,
    width = NA, height = NA, ...)

Arguments

de>matde>

numeric matrix of the values to be plotted.

de>colorde>

vector of colors used in heatmap.

de>kmeans_kde>

the number of kmeans clusters to make, if we want to agggregate the rows before drawing heatmap. If NA then the rows are not aggregated.

de>breaksde>

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 calculated automatically.

de>border_colorde>

color of cell borders on heatmap, use NA if no border should be drawn.

de>cellwidthde>

individual cell width in points. If left as NA, then the values depend on the size of plotting window.

de>cellheightde>

individual cell height in points. If left as NA, then the values depend on the size of plotting window.

de>scalede>

character indicating if the values should be centered and scaled in either the row direction or the column direction, or none. Corresponding values are de>"row"de>, de>"column"de> and de>"none"de>

de>cluster_rowsde>

boolean values determining if rows should be clustered,

de>cluster_colsde>

boolean values determining if columns should be clustered.

de>clustering_distance_rowsde>

distance measure used in clustering rows. Possible values are de>"correlation"de> for Pearson correlation and all the distances supported by de>distde>, such as de>"euclidean"de>, etc. If the value is none of the above it is assumed that a distance matrix is provided.

de>clustering_distance_colsde>

distance measure used in clustering columns. Possible values the same as for clustering_distance_rows.

de>clustering_methodde>

clustering method used. Accepts the same values as de>hclustde>.

de>treeheight_rowde>

the height of a tree for rows, if these are clustered. Default value 50 points.

de>treeheight_colde>

the height of a tree for columns, if these are clustered. Default value 50 points.

de>legendde>

logical to determine if legend should be drawn or not.

de>legend_breaksde>

vector of breakpoints for the legend.

de>legend_labelsde>

vector of labels for the de>legend_breaksde>.

de>annotationde>

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 takes into account if variable is continuous or discrete.

de>annotation_colorsde>

list for specifying annotation track colors manually. It is possible to define the colors for only some of the features. Check examples for details.

de>annotation_legendde>

boolean value showing if the legend for annotation tracks should be drawn.

de>drop_levelsde>

logical to determine if unused levels are also shown in the legend

de>show_rownamesde>

boolean specifying if column names are be shown.

de>show_colnamesde>

boolean specifying if column names are be shown.

de>mainde>

the title of the plot

de>fontsizede>

base fontsize for the plot

de>fontsize_rowde>

fontsize for rownames (Default: fontsize)

de>fontsize_colde>

fontsize for colnames (Default: fontsize)

de>display_numbersde>

logical determining if the numeric values are also printed to the cells.

de>number_formatde>

format strings (C printf style) of the numbers shown in cells. For example "de>%.2fde>" shows 2 decimal places and "de>%.1ede>" shows exponential notation (see more in de>sprintfde>).

de>fontsize_numberde>

fontsize of the numbers displayed in cells

de>filenamede>

file path where to save the picture. Filetype is decided by the extension in the path. Currently following formats are supported: png, pdf, tiff, bmp, jpeg. 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.

de>widthde>

manual option for determining the output file width in

de>heightde>

manual option for determining the output file height in inches.

de>...de>

graphical parameters for the text used in plot. Parameters passed to de>grid.textde>, see de>gparde>.

Details

The function also allows to aggregate the rows using kmeans clustering. This is advisable if number of rows is so big that R cannot handle their hierarchical clustering anymore, roughly more than 1000. Instead of showing all the rows separately one can cluster the rows in advance and show only the cluster centers. The number of clusters can be tuned with parameter kmeans_k.

Value

Invisibly a list of components

  • de>tree_rowde> the clustering of rows as de>hclustde> object

  • de>tree_colde> the clustering of columns as de>hclustde> object

  • de>kmeansde> the kmeans clustering of rows if parameter de>kmeans_kde> was specified

Author(s)

Raivo Kolde <rkolde@gmail.com>

Examples

# 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
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")

# Draw heatmaps
pheatmap(test)
pheatmap(test, kmeans_k = 2)
pheatmap(test, scale = "row", clustering_distance_rows = "correlation")
pheatmap(test, color = colorRampPalette(c("navy", "white", "firebrick3"))(50))
pheatmap(test, cluster_row = FALSE)
pheatmap(test, legend = FALSE)
pheatmap(test, display_numbers = TRUE)
pheatmap(test, display_numbers = TRUE, number_format = "%.1e")
pheatmap(test, cluster_row = FALSE, legend_breaks = -1:4, legend_labels = c("0",
"1e-4", "1e-3", "1e-2", "1e-1", "1"))
pheatmap(test, cellwidth = 15, cellheight = 12, main = "Example heatmap")
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)
annotation$Var1 = factor(annotation$Var1, levels = c("Class1", "Class2", "Class3"))
rownames(annotation) = paste("Test", 1:10, sep = "")

pheatmap(test, annotation = annotation)
pheatmap(test, annotation = annotation, annotation_legend = FALSE)
pheatmap(test, annotation = annotation, annotation_legend = FALSE, drop_levels = 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, main = "Example with all the features")

# Specifying clustering from distance matrix
drows = dist(test, method = "minkowski")
dcols = dist(t(test), method = "minkowski")
pheatmap(test, clustering_distance_rows = drows, clustering_distance_cols = dcols)

Results


draw clustered heatmaps_pheatmap(热图) - 云之南 - 云之南 draw clustered heatmaps_pheatmap(热图) - 云之南 - 云之南 draw clustered heatmaps_pheatmap(热图) - 云之南 - 云之南 draw clustered heatmaps_pheatmap(热图) - 云之南 - 云之南 draw clustered heatmaps_pheatmap(热图) - 云之南 - 云之南 draw clustered heatmaps_pheatmap(热图) - 云之南 - 云之南 draw clustered heatmaps_pheatmap(热图) - 云之南 - 云之南 draw clustered heatmaps_pheatmap(热图) - 云之南 - 云之南 draw clustered heatmaps_pheatmap(热图) - 云之南 - 云之南 draw clustered heatmaps_pheatmap(热图) - 云之南 - 云之南 draw clustered heatmaps_pheatmap(热图) - 云之南 - 云之南 draw clustered heatmaps_pheatmap(热图) - 云之南 - 云之南 draw clustered heatmaps_pheatmap(热图) - 云之南 - 云之南 draw clustered heatmaps_pheatmap(热图) - 云之南 - 云之南 draw clustered heatmaps_pheatmap(热图) - 云之南 - 云之南 draw clustered heatmaps_pheatmap(热图) - 云之南 - 云之南


Created & Maintained by Osamu Ogasawara (osamu.ogasawara@gmail.com)

library("pheatmap")
pheatmap(c,
        border_color="#FFFAEA",
        color = colorRampPalette(rev(c("red","gray90","green")))(102),
        cellwidth=8,cellheight=8,
        fontsize=7,
        cluster_rows=TRUE,cluster_cols=FALSE,
        breaks = c(seq(0, 0.9, length.out = 51), seq(1.1, 6, length.out = 51))

)


  评论这张
 
阅读(8240)| 评论(1)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016