Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print three venn diagrams in the same window

I would like to put together these three venn diagrams. So when I print them, they appear in the same page

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)

thanks!

like image 801
Sergio.pv Avatar asked Apr 10 '14 15:04

Sergio.pv


People also ask

How do you do 3 sets of Venn diagrams?

To solve a Venn diagram with 3 circles, start by entering the number of items in common to all three sets of data. Then enter the remaining number of items in the overlapping region of each pair of sets. Enter the remaining number of items in each individual set. Finally, use any known totals to find missing numbers.


1 Answers

The venn.diagram function is returning gList objects. It seems that the way to arrange them is to first convert them to gTree objects and then plot with the grid.arrange function:

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

like image 179
josliber Avatar answered Oct 18 '22 15:10

josliber