R中的谱图中的x轴和y轴标签 [英] x axis and y axis labels in pheatmap in R
问题描述
我真的很喜欢 pheatmap
包如何在R中创建看起来非常漂亮的热图。但是,我试图将x和y轴标签添加到输出中(如果一个是仅在plot()中,将使用:xlab ='stuff')。一个简单的示例如下。
I really like how the pheatmap
package creates very nice looking heatmaps in R. However, I am trying to add x and y axis labels to the output (if one were just in plot(), one would use: xlab = 'stuff'). A simple example is as follows.
require(pheatmap)
## Generate some data
d <- matrix(rnorm(25), 5, 5)
colnames(d) = paste("bip", 1:5, sep = "")
rownames(d) = paste("blob", 1:5, sep = "")
## Create the heatmap:
pheatmap(d)
以上内容产生了以下热点图:
The above yields the following heatmap:
我一生都无法弄清楚如何添加 xlab或 ylab到这个情节。有什么想法吗?
I cannot for the life of me figure out how to add an 'xlab' or 'ylab' to this plot. Thoughts?
推荐答案
此处的主要问题是谱图
,它使用 grid
软件包,每次调用时都会创建一个新的网格页面。我找到的解决方案是:
The main issue here is that pheatmap
, which uses grid
package, creates a new grid page each time it is called. The solution I've found is:
library(pheatmap)
library(grid)
## Generate some data
d <- matrix(rnorm(25), 5, 5)
colnames(d) = paste("bip", 1:5, sep = "")
rownames(d) = paste("blob", 1:5, sep = "")
## Create the heatmap:
setHook("grid.newpage", function() pushViewport(viewport(x=1,y=1,width=0.9, height=0.9, name="vp", just=c("right","top"))), action="prepend")
pheatmap(d)
setHook("grid.newpage", NULL, "replace")
grid.text("xlabel example", y=-0.07, gp=gpar(fontsize=16))
grid.text("ylabel example", x=-0.07, rot=90, gp=gpar(fontsize=16))
这篇关于R中的谱图中的x轴和y轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!