有什么办法可以将pheatmap
R中的绘图的绘图背景从白色更改为黑色
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
功能结合theme(plot.background = element_rect(colour = 'black', fill = 'black'))
您可以在生成的对象中更改grobs的颜色,方法是pheatmap
:
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 = ""))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句