R heatmap()函数中增加行高 [英] Increasing row height in R heatmap() function

查看:89
本文介绍了R heatmap()函数中增加行高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含数百行和数十列的矩阵,希望绘制一个热图。如果我使用本机R函数:

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))

我得到一个带有模糊行标题的数字。我假设生成的图像与当前绘图设备的规格匹配。我希望控制行的高度,即使该行无法在当前设备上显示。简单地写一个高大的PNG只会在图像上方/下方添加空格:

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()

是否有一种干净的方法可以做到这一点,也许是通过欺骗R认为我有一个非常高的显示器?

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.

推荐答案

前一段时间,我也遇到了同样的问题。 gplots 包中的 heatmap.2 函数解决了该问题。但是,我不太了解查看如此多的基因(或行实验室)有什么好处。但是,按照您的要求,您将执行以下操作:关键是更改热图的 layout (请参见?heatmap.2,?layout),以在2x2网格上绘制热图在绘图设备上(布局中的示例对此进行了更好的说明)。之后,您可能需要通过更改 cexRow rowlabs cex c $ c>相应地。您的情况可能需要一些值来获得所需的结果。

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()

这篇关于R heatmap()函数中增加行高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆