Search code examples
rreshape2venn-diagram

Overriding the sum values for the VennDiagram package


I have a dataset that kind of looks like this:

   ID    X   Y   Z   
1  T1    10  0   10 
2  T2    0   0   20 
3  T3    10  10  40
4  T4    0   30  10
5  T5    0   10  0 
...

I can melt down the data with reshape2 and throw it in the VennDiagram package to visualize the intersections of the dataset. But. I can only visualize counts (not sum totals).

VennDiagram will only recognize T1 as a "1" XZ intersection. I want the package to count "20". And for T3 it shouldn't be just "1" count of XYZ, I want it to sum to "60".

VennDiagram manual: cran.r.project.org

Thanks in advance!

Edit:

The output should look something like this... Where the nrows will sum the totals together

(This current output will just grab the counts)

grid.newpage()
draw.triple.venn(area1 = nrow(subset(accounts, X > 1)),
             area2 = nrow(subset(accounts, Y > 1)), 
             area3 = nrow(subset(accounts, Z > 1)), 
             n12 = nrow(subset(accounts, X > 1 & Y > 1)), 
             n23 = nrow(subset(accounts, Y > 1 & Z > 1)), 
             n13 = nrow(subset(accounts, X > 1 & Z > 1)), 
             n123 = nrow(subset(accounts, X > 1 & Y > 1 & Z > 1)), 
             category = c("X", "Y", "Z"), 
             lty = "blank",
             fill = c("pink1","mediumorchid","skyblue"))

Solution

  • The library(VennDiagram) package doesn't behave as you might expect it to behave.

    You might have a table:

    A1 A2 Overlap 
    1  1  2
    

    And you want the two venn diagram to reflect 1 in the left circle, 1 in the right circle and 2 in the overlap.

    Running this code:

    grid.newpage()
    draw.pairwise.venn(area1 = 1,
                       area2 = 1,
                       cross.area = 2)
    

    Will yield:

    Error in draw.pairwise.venn(area1 = 1, area2 = 1, cross.area = 2) : Impossible: cross section area too large.

    So we have to cheat the venn diagram library by adding the overlap to each area. That way we will get the desired: 1;2;1.

    grid.newpage()
    draw.pairwise.venn(area1 = 1 +  2,
                       area2 = 1 +  2,
                       cross.area = 2)