change line width of dendrogram in pheatmap in R

吃可爱长大的小学妹 提交于 2019-12-23 00:08:54

问题


I have used single cell RNA-seq data stored in a single cell experiment assay to perform hierarchical clustering of ~ 11.3000 expressed genes (not clustering samples) using pheatmap in R to show the heterogeneity of the data. I need the output image to be 2 x 4 inches, which makes the dendrogram a blur. Is it possible to reduce the line width used for the dendrogram? I tried setting the line width by gpar, but it doesn't seem to change

sessionInfo() R version 3.4.1 (2017-06-30) Platform: i386-w64-mingw32/i386 (32-bit) Running under: Windows >= 8 x64 (build 9200) pheatmap_1.0.8

R code

gpar(lwd = 0.5)

pheatmap(assay(sce.tpm),  cellwidth = 10, cellheight= 0.009, fontsize = 5, 
fontsize_row = 6, fontsize_col = 6, 
scale = "row", cluster_cols = F, cluster_rows = T, 
clustering_distance_rows = "euclidean", clustering_method = "average"
color = colorRampPalette(c("blue", "white", "red"))(256), 
show_colnames = T, show_rownames = F)

回答1:


You can directly manipulate the gtable object returned by the pheatmap call. Each grob has a gp parameter that is a gpar object.

library(pheatmap)
library(grid)

set.seed(42)
ph <- pheatmap(matrix(runif(100), nrow = 10), silent = TRUE)

ph$gtable$grobs[[1]]$gp <- gpar(lwd = 5)
ph$gtable$grobs[[2]]$gp <- gpar(col = 'blue')

png('pheatmap_gpar.png', height = 400, width = 400)
grid.newpage()
grid.draw(ph$gtable)
dev.off()

It generates the following clustered heat map:



来源:https://stackoverflow.com/questions/50469883/change-line-width-of-dendrogram-in-pheatmap-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!