有没有办法将R中的pheatmap
情节的情节背景从白色更改为黑色
library(pheatmap)
# Create test matrix
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 = "")
# Draw heatmapspheatmap(test)
pheatmap(test)
我尝试过,但是没有成功
pheatmap(test , bg="black")
或者有没有一种方法可以将pheatmap
与ggplot2
的{{1}}功能结合起来
答案 0 :(得分:0)
您可以更改pheatmap
生成的对象中的grobs颜色:
p <- pheatmap(test)
library(grid)
# Set white color for dendrogram lines and for text
for (k in c(1,2,4,5)) {
p$gtable$grobs[[k]]$gp <- gpar(col="white")
}
p$gtable$grobs[[6]]$children[[2]]$gp <- gpar(col="white", fontsize=10)
# Draw a black box behind the heatmap as background
grid.draw(rectGrob(gp=gpar(fill="black", lwd=0)))
# Draw the heatmap
grid.draw(p)
编辑。正如@Keniajin所建议的,一个较短的解决方案是:
grid.draw(rectGrob(gp=gpar(fill="black", lwd=0)))
grid.draw(p)
grid.gedit("layout", gp = gpar(col = "white", text = ""))