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.
我真的很喜欢pheatmap包在R中创建非常好看的热图。但是,我试图在输出中添加x和y轴标签(如果只是在plot()中,可以使用:xlab ='stuff') 。一个简单的例子如下。
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:
以上产生以下热图:
I cannot for the life of me figure out how to add an 'xlab' or 'ylab' to this plot. Thoughts?
我不能为我的生活弄清楚如何在这个情节中添加'xlab'或'ylab'。思考?
1 个解决方案
#1
4
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:
这里的主要问题是使用网格包的pheatmap每次调用时都会创建一个新的网格页面。我发现的解决方案是:
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))
#1
4
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:
这里的主要问题是使用网格包的pheatmap每次调用时都会创建一个新的网格页面。我发现的解决方案是:
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))