R heatmap()函数中增加行高

编程入门 行业动态 更新时间:2024-10-27 04:36:12
本文介绍了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 相应地。您的情况可能需要一些值来获得所需的结果。

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()函数中增加行高

本文发布于:2023-11-23 01:52:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619680.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   heatmap

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!