pheatmap:绘制聚类热图的函数_pheatmap基于kmeans绘制热图-程序员宅基地

技术标签: 程序人生  

Description

一个绘制聚类热图的函数,可以更好地控制一些图形参数,如单元大小等。

Usage

pheatmap(mat, color = colorRampPalette(rev(brewer.pal(n = 7, name =
  "RdYlBu")))(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",
  clustering_callback = identity2, cutree_rows = NA, cutree_cols = NA,
  treeheight_row = ifelse((class(cluster_rows) == "hclust") || cluster_rows,
  500), treeheight_col = ifelse((class(cluster_cols) == "hclust") ||
  cluster_cols, 500), legend = TRUE, legend_breaks = NA,
  legend_labels = NA, annotation_row = NA, annotation_col = NA,
  annotation = NA, annotation_colors = NA, annotation_legend = TRUE,
  annotation_names_row = TRUE, annotation_names_col = TRUE,
  drop_levels = TRUE, show_rownames = T, show_colnames = T, main = NA,
  fontsize = 10, fontsize_row = fontsize, fontsize_col = fontsize,
  angle_col = c("270""0""45""90""315"), display_numbers = F,
  number_format = "%.2f", number_color = "grey30", fontsize_number = 0.8
  * fontsize, gaps_row = NULL, gaps_col = NULL, labels_row = NULL,
  labels_col = NULL, filename = NA, width = NA, height = NA,
  silent = FALSE, na_col = "#DDDDDD"...)

Arguments 参数

mat:
numeric matrix of the values to be plotted. 
要绘制的值的数值矩阵。

color:
vector of colors used in heatmap. 
热图中使用的颜色矢量。

kmeans_k:
the number of kmeans clusters to make, if we want to aggregate the rows before drawing heatmap. If NA then the rows are not aggregated.
如果我们想在绘制热图之前聚合行,则要创建的 KMEANS 聚类数。如果为 NA,则不聚合行。

breaks:
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. When breaks do not cover the range of values, then any value larger than max(breaks) will have the largest color and any value lower than min(breaks) will get the lowest color.
一个数字序列,涵盖 MAT 中的值范围,并且比颜色向量长一个元素。用于将值映射到颜色。如果需要将某些值映射到某些颜色或某些值,则很有用。如果值为 NA,则自动计算中断。当 breaks 未覆盖值范围时,任何大于 max(breaks) 的值都将具有最大的颜色,而任何小于 min(breaks) 的值将获得最低的颜色。

border_color:
color of cell borders on heatmap, use NA if no border should be drawn.
热图上单元格边框的颜色,如果不应绘制边框,请使用 NA。

cellwidth:
individual cell width in points. If left as NA, then the values depend on the size of plotting window.
单个单元格宽度(以磅为单位)。如果保留为 NA,则值取决于绘图窗口的大小。

cellheight:
individual cell height in points. If left as NA, then the values depend on the size of plotting window.
单个单元格高度(以磅为单位)。如果保留为 NA,则值取决于绘图窗口的大小。

scale 规模
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"
字符指示值是否应在行方向或列方向上居中和缩放,或者不设。相应的值为 “row”、“column” 和 “none”

cluster_rows:
boolean values determining if rows should be clustered or hclust object,
确定行是聚类还是 hclust 对象的布尔值,

cluster_cols:
boolean values determining if columns should be clustered or hclust object.
确定列是聚簇还是 hclust 对象的布尔值。

clustering_distance_rows:
distance measure used in clustering rows. Possible values are "correlation" for Pearson correlation and all the distances supported by dist, such as "euclidean", etc. If the value is none of the above it is assumed that a distance matrix is provided.
聚类行中使用的距离测量。可能的值是 Pearson 相关性的“相关性”和 dist 支持的所有距离,例如“欧几里得”等。如果该值不是上述值,则假定提供了距离矩阵。

clustering_distance_cols:
distance measure used in clustering columns. Possible values the same as for clustering_distance_rows.
聚类列中使用的距离测量。可能的值与clustering_distance_rows的值相同。

clustering_method:
clustering method used. Accepts the same values as hclust.
使用的聚类方法。接受与 hclust 相同的值。

clustering_callback:
callback function to modify the clustering. Is called with two parameters: original hclust object and the matrix used for clustering. Must return a hclust object.
回调函数来修改聚类。使用两个参数调用:原始 hclust 对象和用于聚类的矩阵。必须返回一个 hclust 对象。

cutree_rows:
number of clusters the rows are divided into, based on the hierarchical clustering (using cutree), if rows are not clustered, the argument is ignored
根据分层聚类(使用 Cutree),将行划分为多个聚类,如果行未聚类,则忽略该参数

cutree_cols:
similar to cutree_rows, but for columns 与 cutree_rows 类似,但适用于列

treeheight_row:
the height of a tree for rows, if these are clustered. Default value 50 points.
行的树的高度(如果这些行是聚类的)。 默认值 50 磅。

treeheight_col:
the height of a tree for columns, if these are clustered. Default value 50 points.
列的树的高度,如果这些列是聚类的。 默认值 50 磅。

legend:
logical to determine if legend should be drawn or not.
逻辑来确定是否应绘制图例。

legend_breaks:
vector of breakpoints for the legend. 图例的断点向量。

legend_labels:
vector of labels for the legend_breaks. legend_breaks标签的向量。

annotation_row:
data frame that specifies the annotations shown on left side of the heatmap. Each row defines the features for a specific row. The rows in the data and in the annotation are matched using corresponding row names. Note that color schemes takes into account if variable is continuous or discrete.
指定热图左侧显示的注释的数据框。每行定义特定行的特征。数据和注释中的行使用相应的行名进行匹配。请注意,配色方案会考虑变量是连续的还是离散的。

annotation_col:
similar to annotation_row, but for columns. 与 annotation_row 类似,但适用于列。

annotation:
deprecated parameter that currently sets the annotation_col if it is missing
已弃用的参数,该参数当前设置缺少annotation_col

annotation_colors:
list for specifying annotation_row and annotation_col track colors manually. It is possible to define the colors for only some of the features. Check examples for details.
用于手动指定annotation_row和annotation_col轨道颜色的列表。可以仅定义某些特征的颜色。有关详细信息,请查看示例。

annotation_legend:
boolean value showing if the legend for annotation tracks should be drawn.
显示是否应绘制注释轨迹图例的布尔值。

annotation_names_row:
boolean value showing if the names for row annotation tracks should be drawn.
显示是否应绘制行注释轨道名称的布尔值。

annotation_names_col:
boolean value showing if the names for column annotation tracks should be drawn.
显示是否应绘制列注释轨道名称的布尔值。

drop_levels:
logical to determine if unused levels are also shown in the legend
逻辑以确定图例中是否也显示未使用的级别

show_rownames:
boolean specifying if column names are be shown. boolean 指定是否显示列名。

show_colnames:
boolean specifying if column names are be shown. boolean 指定是否显示列名。

main:
the title of the plot 标题

fontsize:
base fontsize for the plot 绘图的基本字体大小

fontsize_row:
fontsize for rownames (Default: fontsize) 行名的 fontsize (默认值:fontsize)

fontsize_col:
fontsize for colnames (Default: fontsize) colnames 的 fontsize (默认值:fontsize)

angle_col:
angle of the column labels, right now one can choose only from few predefined options (0, 45, 90, 270 and 315)
列标签的角度,现在只能从几个预定义选项(0、45、90、270 和 315)中进行选择

display_numbers:
logical determining if the numeric values are also printed to the cells. If this is a matrix (with same dimensions as original matrix), the contents of the matrix are shown instead of original values.
逻辑确定数值是否也打印到单元格。如果这是一个矩阵(与原始矩阵具有相同的维度),则显示矩阵的内容而不是原始值。

number_format:
format strings (C printf style) of the numbers shown in cells. For example "%.2f" shows 2 decimal places and "%.1e" shows exponential notation (see more in sprintf).
格式字符串(C printf 样式)显示在单元格中的数字。 例如,“%.2f”显示 2 位小数,“%.1e”显示指数表示法(在 sprintf 中查看更多信息)。

number_color:
color of the text 文本的颜色

fontsize_number:
fontsize of the numbers displayed in cells 单元格中显示的数字的字体大小

gaps_row:
vector of row indices that show where to put gaps into heatmap. Used only if the rows are not clustered. See cutree_row to see how to introduce gaps to clustered rows.
行索引的向量,显示在热图中放置间隙的位置。仅当行未聚类时才使用。请参阅cutree_row,了解如何将间隙引入簇行。

gaps_col:
similar to gaps_row, but for columns. 与 gaps_row 类似,但适用于列。

labels_row:
custom labels for rows that are used instead of rownames.
用于代替行名的行的自定义标签。

labels_col:
similar to labels_row, but for columns. 与 labels_row 类似,但适用于列。

filename:
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.
保存图片的文件路径。文件类型由路径中的扩展名决定。目前支持以下格式:png、pdf、tiff、bmp、jpeg。即使绘图不适合打印窗口,也会计算文件大小,以便绘图适合打印窗口,除非另有说明。

width:
manual option for determining the output file width in inches.
用于确定输出文件宽度(以英寸为单位)的手动选项。

height:
manual option for determining the output file height in inches.
用于确定输出文件高度(以英寸为单位)的手动选项。

silent:
do not draw the plot (useful when using the gtable output)
不绘制绘图(使用 GTABLE 输出时很有用)

na_col:
specify the color of the NA cell in the matrix. 指定矩阵中 NA 单元格的颜色。


graphical parameters for the text used in plot. Parameters passed to grid.text, see gpar.
绘图中使用的文本的图形参数。传递给 grid.text 的参数,请参阅 gpar。

Value 值

Invisibly: 
a pheatmap object that is a list with components
pheatmap 对象,它是包含组件的列表

tree_row: 
the clustering of rows as hclust object tree_row行的聚类作为 hclust 对象

tree_col: 
the clustering of columns as hclust object
列的聚类作为 hclust 对象

kmeans: 
the kmeans clustering of rows if parameter kmeans_k was specified
表示如果指定了参数 kmeans_k,则行的 kmeans 聚类

gtable: 
a gtable object containing the heatmap, can be used for combining the heatmap with other plots
包含热图的 gtable 对象可用于将热图与其他图组合在一起

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.

该函数还允许使用 kmeans 聚类聚合行。如果行数太大,以至于 R 无法再处理其分层聚类,大约超过 1000 行,则建议这样做。与其单独显示所有行,不如提前对行进行聚类,并仅显示聚类中心。 可以通过参数kmeans_k调整集群的数量。

Examples 例子

if(!require('pheatmap')) {
    
    install.packages('pheatmap')
    library('pheatmap')
}



# Create test matrix
test = matrix(rnorm(200), 2010)
test[1:10, seq(1102)] = test[1:10, seq(1102)] + 3
test[11:20, seq(2102)] = test[11:20, seq(2102)] + 2
test[15:20, seq(2102)] = test[15:20, seq(2102)] + 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)

# Show text within cells
pheatmap(test, display_numbers = TRUE)
pheatmap(test, display_numbers = TRUE, number_format = "\\%.1e")
pheatmap(test, display_numbers = matrix(ifelse(test > 5"*"""), nrow(test)))
pheatmap(test, cluster_row = FALSE, legend_breaks = -1:4, legend_labels = c("0",
"1e-4""1e-3""1e-2""1e-1""1"))

# Fix cell sizes and save to file with correct size
pheatmap(test, cellwidth = 15, cellheight = 12, main = "Example heatmap")
pheatmap(test, cellwidth = 15, cellheight = 12, fontsize = 8, filename = "test.pdf")

# Generate annotations for rows and columns
annotation_col = data.frame(
                    CellType = factor(rep(c("CT1""CT2"), 5)), 
                    Time = 1:5
                )
rownames(annotation_col) = paste("Test"1:10, sep = "")

annotation_row = data.frame(
                    GeneClass = factor(rep(c("Path1""Path2""Path3"), c(1046)))
                )
rownames(annotation_row) = paste("Gene"1:20, sep = "")

# Display row and color annotations
pheatmap(test, annotation_col = annotation_col)
pheatmap(test, annotation_col = annotation_col, annotation_legend = FALSE)
pheatmap(test, annotation_col = annotation_col, annotation_row = annotation_row)

# Change angle of text in the columns
pheatmap(test, annotation_col = annotation_col, annotation_row = annotation_row, angle_col = "45")
pheatmap(test, annotation_col = annotation_col, angle_col = "0")

# Specify colors
ann_colors = list(
    Time = c("white""firebrick"),
    CellType = c(CT1 = "#1B9E77", CT2 = "#D95F02"),
    GeneClass = c(Path1 = "#7570B3", Path2 = "#E7298A", Path3 = "#66A61E")
)

pheatmap(test, annotation_col = annotation_col, annotation_colors = ann_colors, main = "Title")
pheatmap(test, annotation_col = annotation_col, annotation_row = annotation_row, 
         annotation_colors = ann_colors)
pheatmap(test, annotation_col = annotation_col, annotation_colors = ann_colors[2]) 

# Gaps in heatmaps
pheatmap(test, annotation_col = annotation_col, cluster_rows = FALSE, gaps_row = c(1014))
pheatmap(test, annotation_col = annotation_col, cluster_rows = FALSE, gaps_row = c(1014), 
         cutree_col = 2)

# Show custom strings as row/col names
labels_row = c(""""""""""""""""""""""""""""""
"""""Il10""Il15""Il1b")

pheatmap(test, annotation_col = annotation_col, labels_row = labels_row)

# 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)

# Modify ordering of the clusters using clustering callback option
callback = function(hc, mat){
    sv = svd(t(mat))$v[,1]
    dend = reorder(as.dendrogram(hc), wts = sv)
    as.hclust(dend)
}

pheatmap(test, clustering_callback = callback)

# Same using dendsort package
library(dendsort)

callback = function(hc, ...){dendsort(hc)}
pheatmap(test, clustering_callback = callback)
# }

alt

更多 生物信息学 信息,请关注微信公众号:Everything In Life

持续更新中。。。 alt

来源:https://www.rdocumentation.org/packages/pheatmap/versions/1.0.12/topics/pheatmap

本文由 mdnice 多平台发布

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/ranshan_/article/details/137085284

智能推荐

51单片机的中断系统_51单片机中断篇-程序员宅基地

文章浏览阅读3.3k次,点赞7次,收藏39次。CPU 执行现行程序的过程中,出现某些急需处理的异常情况或特殊请求,CPU暂时中止现行程序,而转去对异常情况或特殊请求进行处理,处理完毕后再返回现行程序断点处,继续执行原程序。void 函数名(void) interrupt n using m {中断函数内容 //尽量精简 }编译器会把该函数转化为中断函数,表示中断源编号为n,中断源对应一个中断入口地址,而中断入口地址的内容为跳转指令,转入本函数。using m用于指定本函数内部使用的工作寄存器组,m取值为0~3。该修饰符可省略,由编译器自动分配。_51单片机中断篇

oracle项目经验求职,网络工程师简历中的项目经验怎么写-程序员宅基地

文章浏览阅读396次。项目经验(案例一)项目时间:2009-10 - 2009-12项目名称:中驰别克信息化管理整改完善项目描述:项目介绍一,建立中驰别克硬件档案(PC,服务器,网络设备,办公设备等)二,建立中驰别克软件档案(每台PC安装的软件,财务,HR,OA,专用系统等)三,能过建立的档案对中驰别克信息化办公环境优化(合理使用ADSL宽带资源,对域进行调整,对文件服务器进行优化,对共享打印机进行调整)四,优化完成后..._网络工程师项目经历

LVS四层负载均衡集群-程序员宅基地

文章浏览阅读1k次,点赞31次,收藏30次。LVS:Linux Virtual Server,负载调度器,内核集成, 阿里的四层SLB(Server Load Balance)是基于LVS+keepalived实现。NATTUNDR优点端口转换WAN性能最好缺点性能瓶颈服务器支持隧道模式不支持跨网段真实服务器要求anyTunneling支持网络private(私网)LAN/WAN(私网/公网)LAN(私网)真实服务器数量High (100)High (100)真实服务器网关lvs内网地址。

「技术综述」一文道尽传统图像降噪方法_噪声很大的图片可以降噪吗-程序员宅基地

文章浏览阅读899次。https://www.toutiao.com/a6713171323893318151/作者 | 黄小邪/言有三编辑 | 黄小邪/言有三图像预处理算法的好坏直接关系到后续图像处理的效果,如图像分割、目标识别、边缘提取等,为了获取高质量的数字图像,很多时候都需要对图像进行降噪处理,尽可能的保持原始信息完整性(即主要特征)的同时,又能够去除信号中无用的信息。并且,降噪还引出了一..._噪声很大的图片可以降噪吗

Effective Java 【对于所有对象都通用的方法】第13条 谨慎地覆盖clone_为继承设计类有两种选择,但无论选择其中的-程序员宅基地

文章浏览阅读152次。目录谨慎地覆盖cloneCloneable接口并没有包含任何方法,那么它到底有什么作用呢?Object类中的clone()方法如何重写好一个clone()方法1.对于数组类型我可以采用clone()方法的递归2.如果对象是非数组,建议提供拷贝构造器(copy constructor)或者拷贝工厂(copy factory)3.如果为线程安全的类重写clone()方法4.如果为需要被继承的类重写clone()方法总结谨慎地覆盖cloneCloneable接口地目的是作为对象的一个mixin接口(详见第20_为继承设计类有两种选择,但无论选择其中的

毕业设计 基于协同过滤的电影推荐系统-程序员宅基地

文章浏览阅读958次,点赞21次,收藏24次。今天学长向大家分享一个毕业设计项目基于协同过滤的电影推荐系统项目运行效果:项目获取:https://gitee.com/assistant-a/project-sharing21世纪是信息化时代,随着信息技术和网络技术的发展,信息化已经渗透到人们日常生活的各个方面,人们可以随时随地浏览到海量信息,但是这些大量信息千差万别,需要费事费力的筛选、甄别自己喜欢或者感兴趣的数据。对网络电影服务来说,需要用到优秀的协同过滤推荐功能去辅助整个系统。系统基于Python技术,使用UML建模,采用Django框架组合进行设

随便推点

你想要的10G SFP+光模块大全都在这里-程序员宅基地

文章浏览阅读614次。10G SFP+光模块被广泛应用于10G以太网中,在下一代移动网络、固定接入网、城域网、以及数据中心等领域非常常见。下面易天光通信(ETU-LINK)就为大家一一盘点下10G SFP+光模块都有哪些吧。一、10G SFP+双纤光模块10G SFP+双纤光模块是一种常规的光模块,有两个LC光纤接口,传输距离最远可达100公里,常用的10G SFP+双纤光模块有10G SFP+ SR、10G SFP+ LR,其中10G SFP+ SR的传输距离为300米,10G SFP+ LR的传输距离为10公里。_10g sfp+

计算机毕业设计Node.js+Vue基于Web美食网站设计(程序+源码+LW+部署)_基于vue美食网站源码-程序员宅基地

文章浏览阅读239次。该项目含有源码、文档、程序、数据库、配套开发软件、软件安装教程。欢迎交流项目运行环境配置:项目技术:Express框架 + Node.js+ Vue 等等组成,B/S模式 +Vscode管理+前后端分离等等。环境需要1.运行环境:最好是Nodejs最新版,我们在这个版本上开发的。其他版本理论上也可以。2.开发环境:Vscode或HbuilderX都可以。推荐HbuilderX;3.mysql环境:建议是用5.7版本均可4.硬件环境:windows 7/8/10 1G内存以上;_基于vue美食网站源码

oldwain随便写@hexun-程序员宅基地

文章浏览阅读62次。oldwain随便写@hexun链接:http://oldwain.blog.hexun.com/ ...

渗透测试-SQL注入-SQLMap工具_sqlmap拖库-程序员宅基地

文章浏览阅读843次,点赞16次,收藏22次。用这个工具扫描其它网站时,要注意法律问题,同时也比较慢,所以我们以之前写的登录页面为例子扫描。_sqlmap拖库

origin三图合一_神教程:Origin也能玩转图片拼接组合排版-程序员宅基地

文章浏览阅读1.5w次,点赞5次,收藏38次。Origin也能玩转图片的拼接组合排版谭编(华南师范大学学报编辑部,广州 510631)通常,我们利用Origin软件能非常快捷地绘制出一张单独的绘图。但是,我们在论文的撰写过程中,经常需要将多种科学实验图片(电镜图、示意图、曲线图等)组合在一张图片中。大多数人都是采用PPT、Adobe Illustrator、CorelDraw等软件对多种不同类型的图进行拼接的。那么,利用Origin软件能否实..._origin怎么把三个图做到一张图上

51单片机智能电风扇控制系统proteus仿真设计( 仿真+程序+原理图+报告+讲解视频)_电风扇模拟控制系统设计-程序员宅基地

文章浏览阅读4.2k次,点赞4次,收藏51次。51单片机智能电风扇控制系统仿真设计( proteus仿真+程序+原理图+报告+讲解视频)仿真图proteus7.8及以上 程序编译器:keil 4/keil 5 编程语言:C语言 设计编号:S0042。_电风扇模拟控制系统设计