minwenwen的个人博客分享 http://blog.sciencenet.cn/u/minwenwen

博文

基于R语言ComplexHeatmap包画带星热图

已有 1291 次阅读 2023-3-5 10:32 |个人分类:博文|系统分类:科研笔记

# 画热图的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://blog.sciencenet.cn/blog-3508269-1378961.html

上一篇:做生物信息学的感触
下一篇:R语言如何将本脚本位置设置为默认路径
收藏 IP: 112.117.194.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-11-23 00:37

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部