[R] from data.frame to Venn diagram

Rui Barradas rui1174 at sapo.pt
Tue Feb 28 04:41:59 CET 2012


Hello,


Lara Poplarski wrote
> 
> 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
> 
> ______________________________________________
> R-help@ mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

Try this:

# First make a list of where there are 'yes' values in 'm'
mvenn <- lapply(m, function(x) which(x == "yes"))
mvenn

venn.diagram(
	x = mvenn[-5],  # exclude a list element (the 5th)
	filename = "vd_without_5th.tiff",
	cex = 2.5,
	cat.cex = 2.5,
	cat.pos = 0
)

# Doesn't work or I'm missing something
venn.diagram(
	x = mm,
	filename="vd_all.tiff",
	cex = 2.5,
	cat.cex = 2.5,
	cat.pos = 0
)
Error: Incorrect number of elements.

It seems to have a limit...

Hope this helps,

Rui Barradas


--
View this message in context: http://r.789695.n4.nabble.com/from-data-frame-to-Venn-diagram-tp4426642p4426853.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list