B.Mr.W.
B.Mr.W.

Reputation: 19648

Turn Binary Representation into Venn Diagram

I have a dataset that I need to turn into a Venn diagram. the data looks like this:

con1 con2 con3 con4 counts
0.0 0.0 0.0 0.0 4165
0.0 0.0 0.0 1.0 118107
0.0 0.0 1.0 0.0 428978
0.0 0.0 1.0 1.0 32045
0.0 1.0 0.0 0.0 84489
0.0 1.0 0.0 1.0 2199
0.0 1.0 1.0 0.0 67245
0.0 1.0 1.0 1.0 42977
1.0 0.0 0.0 0.0 780948
1.0 0.0 0.0 1.0 40406
1.0 0.0 1.0 0.0 28988
1.0 0.0 1.0 1.0 3559
1.0 1.0 0.0 0.0 9802772
1.0 1.0 0.0 1.0 8890
1.0 1.0 1.0 0.0 6577
1.0 1.0 1.0 1.0 84120

Is there any R package can turn this format into a Venn diagram...

What I have done:

I have looked at VennDiagram package but the way that how you turn that into a Venn diagram need you already have the Venn diagram on a paper, i.e. , you need to manually fill the counts from each area into that function.

What I am looking for is a function that could turn this binary representation into a Venn diagram as it is shown above.

Thanks!

Upvotes: 1

Views: 1123

Answers (1)

user20650
user20650

Reputation: 25894

Using VennCounts and vennDiagram funcrions from the limma package - as shown at link

Limma is not part of CRAN, you can type in these two commands to install limma:

source("http://bioconductor.org/biocLite.R")
biocLite("limma")

Here is how you load the data and draw the Venn diagram:

library("limma")

names(dat)[5] <- "Counts" 
dat <- as.matrix(dat)

class(dat) <- "VennCounts"
vennDiagram(dat)

Data should be a matrix of class "VennCounts" with the name Counts.


Data

dat <- structure(list(
    con1 = c(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1), 
    con2 = c(0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1), 
    con3 = c(0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1), 
    con4 = c(0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1), 
    counts = c(4165L, 118107L, 428978L, 32045L, 84489L, 2199L, 67245L, 42977L, 780948L, 40406L, 28988L, 3559L, 9802772L, 8890L, 6577L, 84120L)
    ), 
    .Names = c("con1", "con2", "con3", "con4", "counts"), 
    class = "data.frame", row.names = c(NA, -16L)
)

Upvotes: 2

Related Questions