Increasing row height in R heatmap() function

↘锁芯ラ 提交于 2019-12-06 01:57:29

问题


I have a matrix with hundreds of rows and tens of columns and wish to plot a heatmap. If I use the native R function:

heatmap(matrix(sample(1:10000),nrow=1000,ncol=10))

I get a figure with illegible row titles. I assume the image is produced to match the specifications of the current plotting device. I'd like control over the height of the rows, even if this can't be displayed on my current device. Simply writing to a tall PNG just adds whitespace above/below the image:

png( '/looks_the_same_with_whitespace.png', width=500, height=1500)
heatmap(matrix(sample(1:10000),nrow=1000,ncol=10))
dev.off()

Is there a clean way to do this, perhaps by fooling R into thinking I have a very tall monitor? A function from a well-supported library is also a fine answer.


回答1:


A while ago, I also faced the same problem. heatmap.2 function from gplots package solved the problem. However, I don't quite see how looking at so many genes (or rowlabs) is beneficial. But as you asked you would do something like this: The key is change the layout (see ?heatmap.2, ?layout) of the heatmap which draws heatmap on a 2x2 grid on the plotting device (the example in ?layout explains this much better). After that, you may want to change the cex of rowlabs by changing cexRow accordingly. Your situation might need a bit of playing around with the values to get the desired result.

library(gplots)

row.scaled.expr <- matrix(sample(1:10000),nrow=1000,ncol=10)

png( 'heatmap_without_whitespace_smaller_row_lab.png', width=500, height=1500)
heatmap.2(row.scaled.expr, dendrogram ='row',
                 Colv=FALSE, col=greenred(800), 
                 key=FALSE, keysize=1.0, symkey=FALSE, density.info='none',
                 trace='none', colsep=1:10,
                 sepcolor='white', sepwidth=0.05,
                 scale="none",cexRow=0.2,cexCol=2,
                 labCol = colnames(row.scaled.expr),                 
                 hclustfun=function(c){hclust(c, method='mcquitty')},
                 lmat=rbind( c(0, 3), c(2,1), c(0,4) ), lhei=c(0.25, 4, 0.25 ),                 
                 )
dev.off()


来源:https://stackoverflow.com/questions/12040240/increasing-row-height-in-r-heatmap-function

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