[R] from data.frame to Venn diagram

Daniel Nordlund djnordlund at frontier.com
Tue Feb 28 04:22:39 CET 2012

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Lara Poplarski
> Sent: Monday, February 27, 2012 5:24 PM
> To: r-help at r-project.org
> Subject: [R] from data.frame to Venn diagram
> Hello All,
> I have a data.frame with this structure:
> m <- matrix(sample(c(rep('yes', 10, replace = TRUE), rep('no', 10,
> replace = TRUE), NA), 500, replace = TRUE), nrow = 100, ncol = 5)
> colnames(m) <- colnames(m, do.NULL = FALSE, prefix = "col")
> m <- as.data.frame(m)
> I need to generate a Venn diagram from this data.frame, displaying the
> various intersections of 'yes' for the different columns. Ideally, the
> circle for each column should be proportional to the number of non-NA
> entries.
> The package "VennDiagram" (described here:
> http://www.biomedcentral.com/1471-2105/12/35) can do all this.
> However, I have not been able to figure out how to transform the
> data.frame into the required list format.
> Any suggestions on how to do this?
> Many thanks,
> Lara


I assume you wish to look at which people answered yes on col1 and which answered yes for col2 and the overlap.  So, something like this might help get you started

C1 <- which(m$col1 == 'yes')
C2 <- which(m$col2 == 'yes')
venn.diagram(list(C1=C1, C2=C2), "c:/tmp/Venn_2set_simple.tiff")

If that is not what you want, then you will need to provide an example of what you want your output to be.

Hope this is helpful,


Daniel Nordlund
Bothell, WA USA

More information about the R-help mailing list