【问题标题】:Manhattan plot to be saved with a transparent background曼哈顿地块以透明背景保存
【发布时间】:2018-12-18 12:47:58
【问题描述】:

有一个曼哈顿图,尝试使用 ggsave 保存它:

library(qqman)
MH <- manhattan(gwasResults2, chr="CHR", bp="BP", snp="SNP", p="P", 
                     col = c("chartreuse2", "darkorange1", "gold1"),ylim=c(0,-log10(1e-06)), chrlabs = NULL,
                     suggestiveline = -log10(1e-03), genomewideline = -log10(1e-05),
                     highlight = NULL, logp = TRUE, annotatePval = NULL,
                     annotateTop = TRUE, main='DWStem') + theme_bw() + theme(panel.background = element_rect(fill = "transparent",colour = NA),
                                                                             plot.background = element_rect(fill = "transparent",colour = NA))
ggsave("DWSte.png",MH, bg = "transparent")

文件已生成,但完全空白,我的意思是情节没有出现。

有什么想法吗!?

谢谢:)

【问题讨论】:

标签: r ggplot2 themes bioinformatics genetics


【解决方案1】:

似乎qqman 包中的manhattan 函数与ggplot2:ggsave 不兼容,因为它使用的是基本图形而不是grid 图形。如果您愿意,请使用getAnywhere(manhattan) 检查manhattan 函数背后的代码。

试试这个:

library(qqman)
library(grid)
library(gridGraphics)
library(ggplot2)

# your plot, but without the ggplot2 theme lines (they do nothing anyways)
manhattan(gwasResults, chr="CHR", bp="BP", snp="SNP", p="P", 
          col = c("chartreuse2", "darkorange1", "gold1"),
          ylim = c(0, -log10(1e-06)), chrlabs = NULL,
          suggestiveline = -log10(1e-03), genomewideline = -log10(1e-05),
          highlight = NULL, logp = TRUE, annotatePval = NULL,
          annotateTop = TRUE, main='DWStem')
# Transform the base plot to grobs, so that is compatible with grid and, therefore ggsave
p <- recordPlot()
g <- grid.grabExpr(grid.echo(p))
ggsave("DWSte.png", g, bg = "transparent")

另外,this tutorial 似乎给出了ggplot2 的解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-18
    • 1970-01-01
    • 1970-01-01
    • 2013-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多