pheatmap热图

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

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

画板出现问题:dev.off()

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

在这里插入图片描述

pheatmap(test, cellwidth = 15, cellheight = 12, fontsize = 8, filename = “test.pdf”)

为行和列生成注释

Display row and color annotations

annotation_col = data.frame(
  CellType = factor(rep(c("CT1", "CT2"), 5))

在这里插入图片描述

pheatmap(test, annotation_col = annotation_col) #annotation_col

在这里插入图片描述

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

在这里插入图片描述

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(10, 14))在这里插入图片描述

pheatmap(test, annotation_col = annotation_col, cluster_rows = FALSE, gaps_row = c(10, 14),
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)
在这里插入图片描述

Not run:

Same using dendsort package

library(dendsort)

callback = function(hc, …){dendsort(hc)}
pheatmap(test, clustering_callback = callback)
在这里插入图片描述

End(Not run)

制作不易,麻烦点赞

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

皮肤小白生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值