5

我已经使用这里给出的食谱取得了很大的成功。但是,在过去的几天里,这似乎不起作用。我的sessionInfo()样子如下:

R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] VennDiagram_1.5.1

loaded via a namespace (and not attached):
[1] tools_2.15.2 

我尝试了以下方法,但没有产生任何结果:

 require(VennDiagram)

 venn.diagram(list(B = 1:1800, A = 1571:2020),fill = c("red", "green"), alpha = c(0.5, 0.5), cex = 2,cat.fontface = 4,lty =2, fontfamily =3, filename = "trial2.emf")

但没有产生任何结果。

我做错什么了吗?

4

2 回答 2

12

一种解决方法是使用png()pdf()保存绘图。我们首先确认我们可以使用以下方法在屏幕上绘制绘图grid.draw()

library(VennDiagram)
temp <- venn.diagram(list(B = 1:1800, A = 1571:2020),
    fill = c("red", "green"), alpha = c(0.5, 0.5), cex = 2,cat.fontface = 4,
    lty =2, fontfamily =3, filename = NULL)
grid.draw(temp)

确认后,我们需要做的就是grid.draw()保存pdf()dev.off()

library(grDevices)

pdf(file="venn.pdf")
    grid.draw(temp)
dev.off()

如他们的帮助文件中所述,pdf()并且png()具有控制图像大小等参数的参数,从而提高了对图像质量的控制。

于 2013-01-10T18:47:43.190 回答
7

MattBagg 的回答非常好,但为了完整起见,让我添加如何在同一页面中保存多个维恩图 - 在比较多个条件时很有用。像这样:这个解决方案是 MattBagg 和nmel 的在此处输入图像描述答案的混搭,包含在 pdf() 函数中。

# libraries
library(VennDiagram)
library(grid)
library(gridBase)
library(lattice)

# create the diagrams
temp1 <- venn.diagram(list(B = 1:1800, A = 1571:2020),
    fill = c("red", "green"), alpha = c(0.5, 0.5), cex = 1,cat.fontface = 2,
    lty =2, filename = NULL)
temp2 <- venn.diagram(list(A = 1:1800, B = 1571:2020),
    fill = c("red", "green"), alpha = c(0.5, 0.5), cex = 1,cat.fontface = 2,
    lty =2, filename = NULL)    


# start new page
plot.new() 

pdf("testpdf", width = 14, height = 7)
# setup layout
gl <- grid.layout(nrow=1, ncol=2)
# grid.show.layout(gl)

# setup viewports
vp.1 <- viewport(layout.pos.col=1, layout.pos.row=1) 
vp.2 <- viewport(layout.pos.col=2, layout.pos.row=1) 

# init layout
pushViewport(viewport(layout=gl))
# access the first position
pushViewport(vp.1)

# start new base graphics in first viewport
par(new=TRUE, fig=gridFIG())

grid.draw(temp2)

# done with the first viewport
popViewport()

# move to the next viewport
pushViewport(vp.2)

  grid.draw(temp2)

# done with this viewport
popViewport(1)

dev.off()
于 2013-03-27T10:37:35.497 回答