前面那个帖子我们讲了如何提取monocle2的结果,然后利用pheatmap自己可以进行多方位的美化。今天我们测试一下如何利用complexheatmap进行更多的美化,因为相对来说complexheatmap能做更多的控制和美化。
annotation_col = data.frame(
pseudotime = rescale(newdata$Pseudotime, to = c(-1, 1)))
row.names(annotation_col) <- colnames(m)
annotation_row <- data.frame(Cluster=factor(cutree(p1$tree_row, 4)))
row.names(annotation_row) <- rownames(m)
rowcolor <- c("#85B22E","#E29827","#922927",'#57C3F3')
names(rowcolor) <- c("1","2","3","4") #类型颜色
ann_colors <- list(pseudotime=viridis(100),
Cluster=rowcolor) #颜色设置
p1 <- pheatmap(m,
useRaster = T,
cluster_cols=FALSE,
cluster_rows=T,
show_rownames=F,
show_colnames=F,
clustering_method = "ward.D2",
clustering_distance_rows=row_dist,
cutree_rows=4,
border_color = NA,
filename=NA,
color=colorRampPalette(c("navy","white","firebrick3"))(100),
annotation_col = annotation_col,
annotation_colors=ann_colors,
annotation_row = annotation_row,
)
#这是上次我们用pheatmap做测测试结果。
=====complexheatmap=======
col_fun = colorRamp2(c(-1, 0, 1), c("#440154FF", "#218F8DFF", "#FDE725FF"))
ha = HeatmapAnnotation(Pseudotime = rescale(newdata$Pseudotime, to = c(-1, 1)),
col=list(Pseudotime=col_fun),
show_legend = c("bar" = FALSE)
)
annotation_row$Cluster <- factor(annotation_row$Cluster,levels=c(3,2,4,1))
ht <- Heatmap(m, show_row_names = FALSE, show_column_names = FALSE,cluster_columns=FALSE,
col=colorRampPalette(c("navy","white","firebrick3"))(100),
show_row_dend = FALSE, show_column_dend = FALSE,
row_title_gp = gpar(fill = c("#85B22E","#E29827","#922927",'#57C3F3'), font = 1:4),
top_annotation = ha,
row_split = annotation_row)
ht
======加入GO/KEGG富集结果======
利用我们学习的complexheatmap的技巧,和富集的GO结合起来:
gb <- paste("GO:00001\nGO:00002") #只是简单的做下测试
panel_fun = function(index, nm) {
grid.rect(gp = gpar(fill = "#C3DBF7", col = NA))
grid.text(gb)
}
ht + rowAnnotation(GO = anno_link(align_to = align_to[[1]], which = "row",
panel_fun = panel_fun, size = unit(length(align_to[[1]])/3, "mm"),
width = unit(50, "mm") + unit(5, "mm"),
link_gp = gpar(fill = "#F27F22", col = NA)
))
#根据分割的位置信息,加入其它cluster的注释
panel_fun = function(index, nm) {
# background
grid.rect(gp = gpar(fill ="#C3DBF7", col = NA))
grid.text("GO:00001\nGO:00002")
}
gbl_h <- c(length(align_to[[1]])/3,length(align_to[[2]])/3,
length(align_to[[3]])/3,length(align_to[[4]])/3)
align_to = split(seq_len(nrow(m)),annotation_row)
ht + rowAnnotation(GO = anno_link(align_to = align_to, which = "row",
panel_fun = panel_fun, size = unit(gbl_h,"mm"),
width = unit(70, "mm") + unit(5, "mm"),
link_gp = gpar(fill = "#F27F22", col = NA)
))
网友评论