pheatmap自定义颜色与ggplot2画热图

# pheatmap默认颜色
colors = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(100)

# 其他自定义颜色
bks <- seq(0,1, by = 0.01)
color.use <- rev(RColorBrewer::brewer.pal(n=10, name='Spectral'))
hmcols <- colorRampPalette(color.use)(length(bks) - 1)

pheatmap(xxx, breaks=bks, color=hmcols)

pheatmap(all.markers.scale.dat, filename='xxx.png', 
cluster_rows=F, cluster_cols=F, 
cellwidth=0.02, cellheight=10, fontsize=8, border_color='NA', 
annotation_col=annotation_col, annotation_colors=ann_colors, gaps_col=gap_cell_type,
color=viridis:: plasma(100), breaks=seq(0,1,length.out=100), show_colnames=F)

pheatmap在矩阵中添加NA以在gap之间显示灰色线条

insert_empty <- function(mat, indices, fold) {
    for (index in sort(indices, decreasing = TRUE)) {
    mat <- cbind(mat[,1:index], matrix(rep(NA, fold*nrow(mat)), nrow(mat), fold), mat[,(index+1):ncol(mat)])
    }
    return(mat)
}
mat.adj <- insert_empty(all.markers.scale.mat, gap_cell_type, 20)

ggplot画热图


color.use <- rev(RColorBrewer::brewer.pal(n=10, name='Spectral'))
colors <- colorRampPalette(color.use)(99)
pdf(file='xxx.pdf',width=6,height=3.5)
ggplot(cell.time.dat, aes(x=Time, y=CellType)) + geom_tile(aes(fill=GSVA)) + 
facet_grid(.~Type, scales="free") + 
labs(x='',y='', fill='GSVA\nscore') + 
scale_fill_gradientn(colors=colors, na.value="white", limits=c(quantile(cell.time.dat$GSVA, 0, na.rm= T), quantile(cell.time.dat$GSVA, 1,na.rm= T)), breaks = c(quantile(cell.time.dat$GSVA, 0,na.rm= T), quantile(cell.time.dat$GSVA, 1,na.rm= T)), labels = c("min","max")) + 
theme(axis.text=element_text(size=12, colour='black'),axis.ticks=element_blank(), panel.background=element_blank(), strip.text=element_text(size=10, colour="black"))
dev.off()
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容