我使用了这里给出的配方取得了很大的成功.但是,过去几天这似乎不起作用.我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
Run Code Online (Sandbox Code Playgroud)
我尝试了以下,并没有产生任何结果:
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")
Run Code Online (Sandbox Code Playgroud)
但没有产生任何结果.
我做错了吗?
Mat*_*agg 10
一种解决方法是使用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)
Run Code Online (Sandbox Code Playgroud)
确认之后,我们需要做的就是保存它,重复grid.draw()之间pdf()和dev.off()
library(grDevices)
pdf(file="venn.pdf")
grid.draw(temp)
dev.off()
Run Code Online (Sandbox Code Playgroud)
如其帮助文件中所述,pdf()并png()具有控制图像大小等内容的参数,从而提高对图像质量的控制.
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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7134 次 |
| 最近记录: |