如何在同一窗口中打印三个维恩图

时间:2014-04-10 15:32:05

标签: r plot venn-diagram

我想把这三个维恩图放在一起。因此,当我打印它们时,它们出现在同一页面中

library(VennDiagram)
df1 <- data.frame(G1=sample(1:100, 10), G2=sample(1:100, 10), 
                  G3=sample(1:100, 10), G4=sample(1:100, 10))
venn.plot.df1 <- venn.diagram(x = as.list(df1), filename = NULL,
                            cat.col = c( "black",   "red",     "green3",  "blue" ),
                            fill=c("black",   "red",     "green3",  "blue"))
grid.draw(venn.plot.df1)

df2 <- data.frame(G1=sample(1:100, 10), G2=sample(1:100, 10), 
                  G3=sample(1:100, 10), G4=sample(1:100, 10))
venn.plot.df2 <- venn.diagram(x = as.list(df2), filename = NULL,
                              cat.col = c( "black",   "red",     "green3",  "blue" ),
                              fill=c("black",   "red",     "green3",  "blue"))
grid.draw(venn.plot.df2)

df3 <- data.frame(G1=sample(1:100, 10), G2=sample(1:100, 10), 
                  G3=sample(1:100, 10), G4=sample(1:100, 10))
venn.plot.df3 <- venn.diagram(x = as.list(df3), filename = NULL,
                              cat.col = c( "black",   "red",     "green3",  "blue" ),
                              fill=c("black",   "red",     "green3",  "blue"))
grid.draw(venn.plot.df3)

谢谢!

1 个答案:

答案 0 :(得分:14)

venn.diagram函数返回gList个对象。似乎排列它们的方法是首先将它们转换为gTree个对象,然后使用grid.arrange函数进行绘图:

library(gridExtra)
grid.arrange(gTree(children=venn.plot.df1), gTree(children=venn.plot.df2),
             gTree(children=venn.plot.df3), ncol=3)

enter image description here