Skip to content

from data.frame to Venn diagram

3 messages · Lara Poplarski, Daniel Nordlund, Rui Barradas

#
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
#
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,

Dan

Daniel Nordlund
Bothell, WA USA
#
Hello,


Lara Poplarski wrote
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.