pheatmap实用参数(一)

# Create test matrix
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 = "")
# 编造表达矩阵数据的优秀代码示例

开始画热图

pheatmap(test)  # p1

p1

p1,仅给参数matrix的情况下,可以观察到

  • 数值->色块

  • 横轴Test(分组)进行了聚类(重排)

  • 纵轴Gene 也进行了聚类(重排)

  • 形成了最终的图示效果


pheatmap(test, kmeans_k = 2)  # p2

p2

p2,除了matrix,给出了kmeans_k = 2的参数

  • Gene变成了2个cluster

  • kmeans是聚类算法,这里指定了算法里的k值

  • p1中提到了横纵轴也进行了聚类

关联概念:

什么是聚类?“聚类”和“分类”?不同的聚类思想及聚类算法?kmeans中k值的合理选择?


pheatmap(test, scale = "row", clustering_distance_rows = "correlation")  # p3

p3

p3,参数scale = “row”, clustering_distance_rows = “correlation”

  • 同p1 p2 相比,图例中的数值范围发生了变化

  • 每一行按照Pearson correlation距离度量进行scale操作

  • 每一行中tile之间的相对量趋势没有改变

为了凸显scale参数的作用,先将横纵轴的Hierarchical Clustering去掉,然后截图对比

pheatmap(test, cluster_rows = F, cluster_cols = F)  # extra1
pheatmap(test, cluster_rows = F, cluster_cols = F, scale = "row")  # extra2
pheatmap(test, cluster_rows = F, cluster_cols = F,
         scale = "row", clustering_distance_rows = "correlation")  # extra3

extra1

extra2

extra3


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

p4

p4, color参数,不解释

  • color这里接收的是个vector(vector of colors used in heatmap)

  • colorRampPalette(c(“navy”, “white”, “firebrick3”))(50)这里看起来有点“怪”,
    原因在于colorRampPalette returns a function




参考资料

pheatmap帮助文档

posted @ 2023-03-02 18:41  歪歪ba  阅读(348)  评论(0编辑  收藏  举报