2013-01-09 53 views
3

我用这里给出的配方取得了很多成功。但是,过去几天这似乎不起作用。我sessionInfo()看起来如下:VennDiagram的问题?

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") 

但没有产生任何结果。

我做错了什么?

+0

这适用于我。你能提供更多的信息吗?它怎么没有产生结果?有错误吗?你的会议是空的吗? 'list.files(getwd(),'* .emf')'结果是什么? – Justin

+0

@Justin没有错误,会话不是空的,也没有生成输出文件。没有任何。但可以肯定的是,你能告诉我如何查看会话是否为空? – Sam

+0

空我的意思是“干净”。退出R并重新启动它。然后只运行您在帖子中包含的两个命令。另外,确保你在你认为你的目录中。您可以使用我之前的评论中的两个函数进行排序。 – Justin

回答

7

一个解决方法是使用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) 

已经证实,所有我们需要做的,以保存它是重复作为描述和dev.off()grid.draw()之间pdf()

library(grDevices) 

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

他们的帮助文件,pdf()png()有控制像图像大小的东西的参数,提高对图像质量的控制。

6

MattBagg的回答非常好,但为了完整性,让我添加如何在同一页面中保存多个维恩图 - 在比较多个条件时很有用。就像这样:enter image description here这个解决方案是一个包装在pdf()函数中的MattBagg和nmel's答案的混搭。

# 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()