闵文文
基于R语言ComplexHeatmap包画带星热图
2023-3-5 10:32
阅读:969

# 画热图的R包

library('ComplexHeatmap')

# 调整热图颜色的包

library("circlize")

################################################################################

# 关于此图的说明,请看GitHub上ComplexHeatmap包的介绍

# 见文本的第十部分:10 Integrate with other packages

# https://jokergoo.github.io/ComplexHeatmap-reference/book/integrate-with-other-packages.html


# 开始构造一个仿真数据

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


################################################################################

# 准备行列的分组信息

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


ann_colors = list(

  Time = c("white", "firebrick"),

  CellType = c(CT1 = "#1B9E77", CT2 = "#D95F02"),

  GeneClass = c(Path1 = "#7570B3", Path2 = "#E7298A", Path3 = "#66A61E")

)


################################################################################

# 画带有显著的星图

AA = test-0

ComplexHeatmap::pheatmap(test, 

                         col=colorRamp2(c(0, 2, 4), c("blue","white", "red")),

                         border_color="white",

                         

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

                         number_color    = "white",

                         fontsize_number = 20,  # 星星的大小

                         

                         treeheight_row  = 20,  #调解聚类线的宽度

                         treeheight_col  = 20,  #调解聚类线的宽度

                         

                         annotation_col = annotation_col, 

                         annotation_row  = annotation_row, 

                         annotation_colors = ann_colors)



# pdf("Fun0.pdf", width = 5.4, height = 8.5)

# print(ht)

# dev.off()

################################################################################


转载本文请联系原作者获取授权,同时请注明本文来自闵文文科学网博客。

链接地址:https://wap.sciencenet.cn/blog-3508269-1378961.html?mobile=1

收藏

分享到:

当前推荐数:0
推荐到博客首页
网友评论0 条评论
确定删除指定的回复吗?
确定删除本博文吗?