首先生成测试用的matrix:

library(pheatmap)

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)

rownames(test) = paste("Gene", 1:20, sep = "_")

head(test)

画第一张图

pheatmap(test)

第一个参数

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.看来这个参数是控制将行合并,

>pheatmap(test, kmeans_k = 3)

>pheatmap(test, kmeans_k = 4)

第二张图中的参数

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"

色块的颜色是应该在行方向还是列方向上居中并按比例缩放(应该是归一化)

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.

clustering_distance_cols

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

这两个参数指的是聚类距离的计算方式 皮尔逊相关系数是对欧几里德距离的优化?

> pheatmap(test, scale = "row", clustering_distance_rows = "correlation")

按照行归一化色块颜色,并且行的聚类依据是皮尔逊系数

第三张图中的参数

> pheatmap(test, color = colorRampPalette(c("navy", "white", "firebrick3"))(50))

这个配的很好看,color:vector of colors used in heatmap,应该是指的右边的注释条,这个参数的输入格式应该是一个向量

> pheatmap(test, cluster_row = FALSE)

cluster_rows   boolean values determining if rows should be clustered or hclust object,

cluster_cols    boolean values determining if columns should be clustered or hclust object.

就是说控制行、列的聚类有无

> pheatmap(test, legend = FALSE) -- logical to determine if legend should be drawn or not.

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

> pheatmap(test, display_numbers = TRUE)

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.

输入值是逻辑值则控制色块内部是否显示数值,如果是输入一个矩阵,那么可以显示矩阵的信息,但是必须有与原矩阵一致的维度

> pheatmap(test, display_numbers = TRUE, number_format = "\%.1e")

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

控制表格内部数字的显示格式,是小数点后两位还是科学计数法

pheatmap(test, display_numbers = matrix(ifelse(test > 5, "*", ""), nrow(test)))

matrix(ifelse(test > 5, "*", ""), nrow(test))构建的新矩阵,其实他的代码我没看懂,我根据自己的理解> pheatmap(test, display_numbers = ifelse(test > 5, "*", "")),因为

>ifelse(test > 5, "*", "")的输出结果就是矩阵的形式,可以作为display_numbers的input.

> pheatmap(test, cluster_row = FALSE, legend_breaks = -1:4, legend_labels = c("0","1e-4", "1e-3", "1e-2", "1e-1", "1"))

legend_breaks:vector of breakpoints for the legend.

legend_labels :vector of labels for the legend_breaks—对色度注释进行操作,好像没什么意思。。。。

Lengths of legend_breaks and legend_labels must be the same

# Fix cell sizes and save to file with correct size    好像是没啥用

>pheatmap(test, cellwidth = 15, cellheight = 12, main = "Example heatmap")

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

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

Cell的尺寸,如果不指定那么将根据画板的大小进行自适应。

Main:the title of the plot

>pheatmap(test, cellwidth = 15, cellheight = 12, fontsize = 8, filename = "test.pdf")

Fontsize:base fontsize for the plot

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。 除非另有说明,否则即使绘图不适合绘图窗口,也会计算文件大小,以使绘图适合此处。

# 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(10, 4, 6))))

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)

构建注释数据框,名称要一致

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.

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

angle_col:angle of the column labels, right now one can choose only from few predefined options (0, 45, 90, 270 and 315)

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

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.

注意输入的值是list,可以指定某一个特定注释特征的颜色,比如第三个例子。首先构建了一个list的对象,一共有三个注释Time、CellType、GeneClass,每个注释有不同的level,有几个level就需要设定几种颜色,之后指定annotation_colors的值就行。

# Show custom strings as row/col names

labels_row = c("", "", "", "", "", "", "", "", "", "", "", "", "", "", "",

"", "", "Il10", "Il15", "Il1b")

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

labels_row

custom labels for rows that are used instead of rownames.

labels_col

similar to labels_row, but for columns.

可以理解为不使用行列名,我们自己指定每一列行的名字label

# Specifying clustering from distance matrix

drows = dist(test, m(ethod = "minkowski"))

dcols = dist(t(test), method = "minkowski")

pheatmap(test, clustering_distance_rows = drows, clustering_distance_cols = dcols)

自行计算行列的聚类值

调用dist()

This function computes and returns the distance matrix computed by using the specified distance measure to compute the distances between the rows of a data matrix.

计算矩阵行之间的数值距离,对于列之间的数值距离,巧妙的调用了t()转置函数

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

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.

应该是一种修正聚类结果的参数,可能是聚类结果更为可信

我的避难日记-《R:pheatmap》,热图,heatmap,聚类相关推荐

  1. r语言热图对列不进行聚类_R语言:手把手教你画pheatmap热图

    R语言:手把手教你画pheatmap热图 微生态 导读: pheatmap默认会对输入矩阵数据的行和列同时进行聚类,但是也可以通过布尔型参数cluster_rows和cluster_cols设置是否对 ...

  2. R:热图解释 | pheatmap包参数及详细聚类图绘制流程(一篇解决热图绘制问题)

    热图解释及pheatmap绘制热图 一.热图绘制原理 1.1 热图介绍 1.2 热图绘制准备--均一化 1.3 热图绘制方式 1.4 热图数据查看示例 二.pheatmap包简介 2.1 pheatm ...

  3. Pheatmap热图的绘制及如何调整图片

    Pheatmap热图的绘制及如何调整图片 Pheatmap包是R语言绘制热图比较强大的软件包,当然现在也有很多资料介绍这个包的使用,但是今天我写的重点不是如何使用这个包绘制热图,而是如何绘制出更好看的 ...

  4. 获取pheatmap热图聚类后和标准化后的结果

    pheatmap是简单常用的热图绘制包,可以快速.简单.可定制的绘制漂亮热图.具体见R语言学习-热图简化和免费高颜值可定制在线绘图工具 ImageGP. 现在要解决的一个问题是图出来了,想看下转换后用 ...

  5. R | 可视化 | 热图(Heatmap)

    1 基础绘制 R绘制热图时,数据需要输入一个矩阵,可以用as.matrix()把它转换成矩阵.这里利用R自带的数据集绘制热图. > # 数据 > data <- as.matrix( ...

  6. 如何在R语言中建立六边形矩阵热图heatmap可视化

    原文链接:http://tecdat.cn/?p=18879 这是一个六边形热图可视化程序,主要用到的知识RColorBrewer,fields,也就是R中的可视化绘图库(点击文末"阅读原文 ...

  7. pheatmap热图

    pheatmap热图 # Create test matrix test = matrix(rnorm(200), 20, 10) test[1:10, seq(1, 10, 2)] = test[1 ...

  8. r语言热图对列不进行聚类_R语言 Pheatmap 画非聚类 热图

    python pandas 加 R Pheatmap 画非聚类热图 最近需求一个需求图 f9cb530a4fb553c2f42fd8f157cd451.png 上面的annotation部分用作临床注 ...

  9. 【R】 绘制 热图 heatmap

    最近发现pheatmap画热图挺好看的,有机会也使用一下~~~ http://www.bjt.name/tag/heatmap/ R 绘制 heatmap NBA联盟50位顶级球员的指标表现 介绍如何 ...

  10. 热图 heatmap.2 和 pheatmap

    ```handlebars > getwd() [1] "C:/Users/Administrator/Documents" > setwd("F:/R.wo ...

最新文章

  1. 艾伟:WCF从理论到实践(11)-异步
  2. OpenCV学习笔记之改变图像的对比度和亮度
  3. mysql ssl连接是什么_mysql 的ssl连接是什么
  4. linux中添加一个用户到指定用户组的两种方式,修改一个用户到指定用户组的一种方式...
  5. 第十八节20181216
  6. docker安装前提条件
  7. vmware安装minimal centos报错/etc/rc5.d/s99local : line
  8. 手把手教你用C语言画“心”!
  9. 2.6 Word2Vec
  10. Echarts数据可视化series-graph关系图,开发全解+完美注释
  11. 直接插入排序中的监视哨问题
  12. 参数中带有“”符号问题
  13. 小程序学习笔记(6)-菜谱小程序的制作
  14. 双击图片不放大手机php,Android_Android App中实现可以双击放大和缩小图片功能的实例,先来看一个很简单的核心图片 - phpStudy...
  15. Grub 启动时的 Error 13: Invalid or unsupported executable 问题的解决
  16. mysql数据库技术与应用实训项目_MySQL数据库项目实训
  17. linux启动盘恢复成普通U盘,u盘启动盘还原普通u盘win10 制作
  18. [unity]调用手机摄像头
  19. 进入黑客的世界:Kali Linux 中的 Metasploit 渗透测试利器
  20. Win10 DISM 清理 C盘的 WinSXS 文件夹

热门文章

  1. 首行缩进字符计算机怎么弄,word首行缩进2字符是多少厘米
  2. 傻瓜自己看的笔记:3D放样-叫花子的器皿
  3. kendo ui 动态隐藏列_kendoUI动态改变grid复选框变单选框
  4. 第一次注册机破解,Secure CRT
  5. 禅道邮箱配置163邮箱/阿里云邮箱区别
  6. 我在成都火车站捡了个彝族美女 第64节:聊天记录中的真相
  7. 用Python做中文分词和绘制词云图
  8. vivado的vio怎么使用_Vivado中vio的使用
  9. jdk高版本向下兼容
  10. 让控件飞到指定位置动画