一直感觉用pheatmap绘制的热图,实在是不太美观,虽然可以用ggplotify包转换成ggplot2的格式,但是很多细节也难以调整,果然还是ggplot2绘制的图美感十足
library(ggplot2)
library(ggtree)
library(aplot)
library(tidyr)
p <- scale(mtcars) %>% data.frame()
#绘制行聚类树
phr <- hclust(dist(p)) %>% ggtree(layout="rectangular", branch.length="none")
#绘制列聚类树
phc <- hclust(dist(t(p))) %>% ggtree() + layout_dendrogram()
p$mtxars <- rownames(p)
#宽表转长表
p1 <- gather(p, 1:11, key="condition", value='expr')
#绘制热图
pp <- ggplot(p1,aes(condition,mtxars,fill=expr)) + geom_tile()+
theme_minimal()+
scale_fill_viridis_c() +
scale_y_discrete(position="right")+
xlab(NULL) + ylab(NULL)
#利用aplot包将聚类树与热图拼接
pp %>% insert_left(phr, width=.1) %>%
insert_top(phc, height=.1)

网友评论