参数介绍里面很丰富,但具体细节可能需要多做几张图才能慢慢体会!
下载及练习使用的矩阵在下面代码:
#下载可以通过GitHub和biocmanage两种,前者最新版本,后者稳定版本
library(devtools)
install_github("jokergoo/ComplexHeatmap")
sessionInfo()
library(ComplexHeatmap)
#这个矩阵是官方document提供的
set.seed(123)
nr1 = 4; nr2 = 8; nr3 = 6; nr = nr1 + nr2 + nr3
nc1 = 6; nc2 = 8; nc3 = 10; nc = nc1 + nc2 + nc3
mat = cbind(rbind(matrix(rnorm(nr1*nc1, mean = 1, sd = 0.5), nr = nr1),
matrix(rnorm(nr2*nc1, mean = 0, sd = 0.5), nr = nr2),
matrix(rnorm(nr3*nc1, mean = 0, sd = 0.5), nr = nr3)),
rbind(matrix(rnorm(nr1*nc2, mean = 0, sd = 0.5), nr = nr1),
matrix(rnorm(nr2*nc2, mean = 1, sd = 0.5), nr = nr2),
matrix(rnorm(nr3*nc2, mean = 0, sd = 0.5), nr = nr3)),
rbind(matrix(rnorm(nr1*nc3, mean = 0.5, sd = 0.5), nr = nr1),
matrix(rnorm(nr2*nc3, mean = 0.5, sd = 0.5), nr = nr2),
matrix(rnorm(nr3*nc3, mean = 1, sd = 0.5), nr = nr3))
)
mat = mat[sample(nr, nr), sample(nc, nc)] # random shuffle rows and columns
rownames(mat) = paste0("row", seq_len(nr))
colnames(mat) = paste0("column", seq_len(nc))
直接实战来认识参数
图一
Heatmap(mat,
name = "mat",
col=colorRamp2(c(-2,0,2),c('skyblue2','white','red3')), #颜色设置
color_space = "RGB",
border = T,
cluster_columns = F,
cluster_rows = F,
row_order=NULL,
column_order=NULL,
column_title_side = "bottom", #设置行名及列名具体格式
column_title_gp = gpar(fontsize=13,fondface="bold"),
row_title_gp = gpar(fontsize=13,fondface="bold"),
row_split = factor(c(rep(c("gene A","gene B","gene C"),time= c(4,6,8))), #根据行列分版块
levels = c("gene A","gene B","gene C")),
column_split = factor(c(rep(c("low risk","high risk"),12)),
levels =c("low risk","high risk"),
labels = c("low risk","high risk")),
show_column_names = F)
注释主要用到 HeatmapAnnotation 这个参数,参数使用直接上图来体会
图二
#图二
Heatmap(matrix(rnorm(100), 10),
col = colorRamp2(c(-2,0,2),c("skyblue","white","red3")),
show_row_names = F,
row_split = rep(c("model 1","model 2","model3"),time=c(2,3,5)),
row_title_gp = gpar(fontsize=14,fontface='bold'),
top_annotation = HeatmapAnnotation(foo = anno_block(gp = gpar(fill = 2:4),
labels = c("group1", "group2", "group3"),
labels_gp = gpar(col = "white", fontsize = 10))),
cluster_rows = F,
cluster_columns = F,
column_split = rep(1:3,time=c(2,3,5)),
show_column_names = F)
·
实战一
中的一张简单的热图,热图中5中signature在不同分组 中的表达,注释文件时是
实战一
.
实战一
mat <- matrix(rnorm(500),nrow = 5)
colnames(mat) <- paste0("sample",1:100)
rownames(mat) <- paste0("signature",c(1,16,3,2,13))
cli <- data.frame(Tobacoo=sample(c("No","Yes"),100,replace = T),
Alchoal=sample(c("No","Yes"),100,replace = T),
HPV16=c(sample(c("No","Yes"),30,replace = T),rep("No",20),rep("Yes",30),rep("No",20)),
cluster=rep(c("A","B","C1","C2"),time=c(20,30,30,20)))
cli$Tobacoo <- factor(cli$Tobacoo)
Tobacoo <- c(pal_nejm()(8)[1],pal_nejm()(8)[2])
names(Tobacoo) <- c("Yes","No")
cli$Alchoal <- factor(cli$Alchoal)
Alchoal <- c(pal_nejm()(8)[1],pal_nejm()(8)[2])
names(Alchoal) <-c("Yes","No")
cli$HPV16 <- factor(cli$HPV16)
HPV16<- c(pal_nejm()(8)[1],pal_nejm()(8)[2])
names(HPV16)<- c("Yes","No")
cli$cluster <- factor(cli$cluster)
cluster <- c(pal_nejm()(8)[3],pal_nejm()(8)[4],pal_nejm()(8)[5],pal_nejm()(8)[6])
names(cluster) <- c("A","B","C1","C2")
library(ComplexHeatmap)
library(circlize)
library(ggsci)
Heatmap(mat,col = colorRamp2(c(-2,0,2),c("skyblue2","white","red2")),
color_space = "RGB",
column_split = factor(rep(c("A","B","C"),time=c(20,30,50))),
cluster_columns = F,
show_column_names = F,
top_annotation = HeatmapAnnotation( Tobacoo=cli$Tobacoo,
Alchoal=cli$Alchoal,
HPV16=cli$HPV16,
cluster=cli$cluster,
annotation_legend_param=list(labels_gp = gpar(fontsize = 9),
title_gp = gpar(fontsize = 9, fontface = "bold"),
ncol=1),
col = list(Tobacoo=Tobacoo,
Alchoal=Alchoal,
HPV16=HPV16,
cluster=cluster),
show_annotation_name = TRUE,
annotation_name_side="right",
annotation_name_gp = gpar(fontsize = 9, fontface = "bold")))
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。