0

EDIT: I have the two lists below. They are written exactly as they are presented:

x1 <- list()
x1$A <- as.character(c("Per_36","Cent","CeM","vDG","LAVL","RSGd"))
x1$B <- as.character(c("vCA1","DLE","Per_36","vDG","DIE","Per_35"))
x1$C <- as.character(c("vCA1","Cg1","LAVL", "RSGc", "RSGd","Per_35","Per_36"))
x1$D <- as.character(c("Por","Cg1","RSGc","LAVL","Per_35","RSGd","Per_36"))

x2 <- list()
x2$A <- as.character(c("Per_36","Per_35","Por","vCA1","BLV","Cent","PrL"))
x2$B <- as.character(c("BLA","VIE","BLV","Por","Cent","Ment","dCA1"))
x2$C <- as.character(c("dDG","Per_36","CeM","Per_35","BLV","dCA1","PrL","IL"))
x2$D <- as.character(c("CeC","RSGb","CeL","dDG","CeM","dCA1","PrL","IL"))

They were generated in the exact same way. When I run the function calculate.overlap from VennDiagram package in x1 I get a nice and plot and the function runs perfectly. But when I run in x2, I get an empty list, which clearly is wrong. I just can't see what is wrong in it. Any help??

overlapx1
$a6
[1] "Per_36"

$a12
character(0)

$a11
character(0)

$a5
[1] "LAVL" "RSGd"

$a7
[1] "Per_35"

$a15
[1] "vDG"

$a4
character(0)

$a10
character(0)

$a13
[1] "vCA1"

$a8
character(0)

$a2
[1] "Cg1"  "RSGc"

$a9
[1] "Cent" "CeM" 

$a14
[1] "DLE" "DIE"

$a1
character(0)

$a3
[1] "Por"

When I run overlapx2 <- calculate.overlap(x2) I get an equal list with all vectors of the list = character(0)

EDIT 2: the link to the package is below https://cran.r-project.org/web/packages/VennDiagram/index.html

And the Manual https://cran.r-project.org/web/packages/VennDiagram/VennDiagram.pdf

The Author is Hambo Chen, but it's maintained by Paul Boutros

CAOC
  • 323
  • 5
  • 18
  • 3
    You may want to include your input data using `dput`. If you include the results of `dput(x1)` and `dput(x2)` that would make it easier for others to load the data. – steveb Feb 17 '16 at 17:50
  • hi @steveb, I just edited my question and put the data just as it is. That should be enough to replicate what I did. – CAOC Feb 18 '16 at 00:20
  • A quick look shows one can reproduce this with a simpler example. You may want to ping the authors of the package on this as even a simpler example can show essentially a list of empty vectors. – steveb Feb 18 '16 at 00:50
  • 2
    You may use the `gplots::venn(x2)` function instead. This function can handle multiple-sized venns. Saving the plot in an object allows to get the interactions. `a <- venn(x2); a; attr(a, "intersections")` – Roman Feb 18 '16 at 13:50
  • @Jimbou but how to plot the labels into the the venn diagram generated by 'venn' functions? That's another question I posted here some time ago. link: http://stackoverflow.com/questions/35457611/optimized-venndiagram-with-internal-labels-r In there I use the 'calculate.overlap' function to paste the labels into the venn diagram labels. If I could do it using 'venn' I'd be fine. – CAOC Feb 18 '16 at 15:51

1 Answers1

1

I digged the code in the function and found the error.

I will post just a sample of the code that can serve as the answer and solution for my own question.

calculate.overlap
function (x) 
{
    if (1 == length(x)) {
        overlap <- x
    }
    else if (2 == length(x)) {
        overlap <- list(a1 = x[[1]], a2 = x[[2]], a3 = intersect(x[[1]], 
            x[[2]]))
    }
    else if (3 == length(x)) {
        A <- x[[1]]
        B <- x[[2]]
        C <- x[[3]]
        nab <- intersect(A, B)
        nbc <- intersect(B, C)
        nac <- intersect(A, C)
        nabc <- intersect(nab, C)
        a5 = nabc
        a2 = nab[-which(nab %in% a5)]
        a4 = nac[-which(nac %in% a5)]
        a6 = nbc[-which(nbc %in% a5)]
        a1 = A[-which(A %in% c(a2, a4, a5))]
        a3 = B[-which(B %in% c(a2, a5, a6))]
        a7 = C[-which(C %in% c(a4, a5, a6))]
        overlap <- list(a5 = a5, a2 = a2, a4 = a4, a6 = a6, a1 = a1, 
            a3 = a3, a7 = a7)
    }
#. Purposely took the length(x) == 4 and 5 to shorten it. 
#. rationale is the same ans is simple
#.
    else {
        flog.error("Invalid size of input object", name = "VennDiagramLogger")
        stop("Invalid size of input object")
    }
}
<environment: namespace:VennDiagram>

the bugged operation is the highlighted command below:

a2 = nab[**-which(**nab %in% a5)]

replacing it to

a2 = nab[! nab %in% a5]

does the trick just fine. But it has to be done in all operations in the function.

I will try to contact the author of the package to see if he can update it in the future.

CAOC
  • 323
  • 5
  • 18