将维恩图绘制为 R 中的子图

Plotting venn diagrams as subplots in R

我想在一个图中绘制三个不同的维恩图。我正在为维恩图使用 R VennDiagram 包。对于子图,我尝试了 grid.arrange() 但它给出了

"arrangeGrob" error: "Error in arrangeGrob(..., as.table = as.table, clip = clip, main = main, : input must be grobs!".

以下是我尝试的代码和我的 R 会话信息:

#VennDiagram:
library(VennDiagram)
A<- draw.pairwise.venn(600, 200, 61, c("X", "Y"), col= rep("gray70", 2), lwd= rep (1, 2), fill= c("skyblue1", "yellowgreen"), cat.pos=0, fontfamily = rep("sans"), cat.fontfamily= rep("sans"), sacled=FALSE)

B<- draw.pairwise.venn(400, 200, 60, c("X", "Y"), col= rep("gray70", 2), lwd= rep (1, 2), fill= c("skyblue1", "yellowgreen"), cat.pos=0,, fontfamily = rep("sans"), cat.fontfamily= rep("sans"), scaled=FALSE)

C<- draw.pairwise.venn(700, 500, 75, c("X", "Y"), col= rep("gray70", 2), lwd= rep (1, 2), fill= c("skyblue1", "yellowgreen"), cat.pos=0,, fontfamily = rep("sans"), cat.fontfamily= rep("sans"), scaled=FALSE)

#For subplot:
library(ggplot2)
library(grid)
library(gridExtra)
grid.arrange(A, B, C, ncol = 3, main = "Venn")

#R sessionInfo
sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: x86_64-apple-darwin13.1.0 (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 
[8] base    

other attached packages:
[1] gridExtra_0.9.1   ggplot2_1.0.0     VennDiagram_1.6.9

loaded via a namespace (and not attached):
[1] colorspace_1.2-4 digest_0.6.6     gtable_0.1.2     MASS_7.3-35    
[5] munsell_0.4.2    plyr_1.8.1       proto_0.3-10     Rcpp_0.11.3    
[9] reshape2_1.4.1   scales_0.2.4     stringr_0.6.2    tcltk_3.1.1    
[13] tools_3.1.1 

如果能帮助我绘制不同的维恩图作为子图,我将不胜感激。

显然你解决了你的问题,但你也可以这样做(只用 VennDiagramgrid 包):

pushViewport(viewport(layout=grid.layout(ncol=3, widths = unit(rep(1/3,3), "npc"))))
pushViewport(viewport(layout.pos.col=1))
draw.pairwise.venn(600, 200, 61, c("X", "Y"), col= rep("gray70", 2), lwd= rep (1, 2), fill= c("skyblue1", "yellowgreen"), cat.pos=0, fontfamily = rep("sans"), cat.fontfamily= rep("sans"), sacled=FALSE)
popViewport()
pushViewport(viewport(layout.pos.col=2))
draw.pairwise.venn(400, 200, 60, c("X", "Y"), col= rep("gray70", 2), lwd= rep (1, 2), fill= c("skyblue1", "yellowgreen"), cat.pos=0,, fontfamily = rep("sans"), cat.fontfamily= rep("sans"), scaled=FALSE)
popViewport()
pushViewport(viewport(layout.pos.col=3))
draw.pairwise.venn(700, 500, 75, c("X", "Y"), col= rep("gray70", 2), lwd= rep (1, 2), fill= c("skyblue1", "yellowgreen"), cat.pos=0,, fontfamily = rep("sans"), cat.fontfamily= rep("sans"), scaled=FALSE)
popViewport(0)