r pheatmap:在省略列名时如何为特定的行名进行着色?
在R中使用“ pheatmap”软件包,与Windows 10一起使用RSTUDIO,我可以按照示例(如下所示)只要热图显示行和列名称,就可以产生一个具有选择性着色的热图。但是,如果我尝试生成一个没有显示列名的选择性着色的热图,我会得到一个错误:
“ set.gpar中的错误(x $ gp,grob,grob = x):参数必须是'gpar'对象“
这是热图的借用示例:
library(pheatmap)
test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")
这是借用的借用示例,用于着色选择行名称:
library(grid)
library(gridExtra)
library(pheatmap)
hm <- pheatmap(test, silent = TRUE)
hm$gtable$grobs[[5]]$gp$col <- rep(c("black", "red"), each = 10)
leg <- legendGrob(c("Exp1", "Exp2"), nrow = 2, pch = 15, gp = gpar(fontsize = 10, col = c("black", "red")))
hm2 <- arrangeGrob(hm$gtable, leg, ncol = 2, widths = c(5,1))
grid.draw(hm2)
带有选定的行名称彩色红色的示例热图 但是,如果我尝试创建热图而不显示列的名称如下:
pheatmap(test, show_colnames=FALSE, silent=TRUE)
hm$gtable$grobs[[5]]$gp$col <- rep(c("black", "red"), each = 10)
leg <- legendGrob(c("Exp1", "Exp2"), nrow = 2, pch = 15, gp = gpar(fontsize = 10, col = c("black", "red")))
hm2 <- arrangeGrob(hm$gtable, leg, ncol = 2, widths = c(5,1))
grid.draw(hm2)
然后我会遇到一个错误:
set.gpar中的错误(x $ gp,grob,grob = x):参数必须是'gpar'对象,
- 为什么会出现此错误发生?
- 在不显示列名的同时,如何通过选择性着色来产生热图?
请注意,我更喜欢使用“ pheatmap”软件包。建议使用替代软件包(例如“ ComplexHeatMap”软件包)的答案,但由于各种原因,我希望尽可能使用“ pheatmap”软件包。谢谢。
Using the "pheatmap" package in R, with Rstudio for Windows 10, I can follow an example(as shown here) to produce a heatmap with selective coloring of row names as long as the heatmap displays both row and column names. However, if I try to generate a heatmap with selective coloring of row names without showing the column names, I get an error:
"Error in set.gpar(x$gp, grob = x) : argument must be a 'gpar' object"
Here is a borrowed example of a heatmap:
library(pheatmap)
test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")
And here is a borrowed example of a method for coloring selected row names:
library(grid)
library(gridExtra)
library(pheatmap)
hm <- pheatmap(test, silent = TRUE)
hm$gtable$grobs[[5]]$gp$col <- rep(c("black", "red"), each = 10)
leg <- legendGrob(c("Exp1", "Exp2"), nrow = 2, pch = 15, gp = gpar(fontsize = 10, col = c("black", "red")))
hm2 <- arrangeGrob(hm$gtable, leg, ncol = 2, widths = c(5,1))
grid.draw(hm2)
Sample heatmap with selected row names colored red
However, if I try to create the heatmap without showing the column names as follows:
pheatmap(test, show_colnames=FALSE, silent=TRUE)
hm$gtable$grobs[[5]]$gp$col <- rep(c("black", "red"), each = 10)
leg <- legendGrob(c("Exp1", "Exp2"), nrow = 2, pch = 15, gp = gpar(fontsize = 10, col = c("black", "red")))
hm2 <- arrangeGrob(hm$gtable, leg, ncol = 2, widths = c(5,1))
grid.draw(hm2)
Then I get an error:
Error in set.gpar(x$gp, grob = x) : argument must be a 'gpar' object
- Why does this error occur?
- How could the heatmap be produced with selective coloring of row names while not showing the column names?
Please note that I prefer to use the "pheatmap" package. Answers to similar questions have recommended using alternative packages such as the "ComplexHeatmap" package, but for various reasons, I prefer to use the "pheatmap" package if at all possible. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了获得错误,您的第一行在第三个代码段中应如下:
简单解决方案:
To get the error your first line in the third code snippet should be as follows:
The simple solution: