拥有曼哈顿情节,尝试使用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")
该文件已生成,但完全空白,我的意思是情节没有来临。
有什么主意!?
谢谢:)
答案 0 :(得分:1)
似乎manhattan
包中的qqman
功能与ggplot2:ggsave
不兼容,因为它使用的是基本图形而不是grid
图形。如果需要,请使用manhattan
检查getAnywhere(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
解决方案。