js229 / Vennerable

Vennerable provides Venn diagrams in R. It displays Venn and Euler diagrams for up to 9 different sets and using a variety of geometries. It allows the display of area-weighted Venn diagrams and allows fine graphical control over the result.
90 stars 39 forks source link

Error :length(cutedge) == 1 is not true #36

Closed gk7279 closed 3 years ago

gk7279 commented 8 years ago

Dear js229,

I am trying a 7 set data with vennerable using type=ChowRuskey and I see this error message.

I even tried doWeights=F, but it didnt help.

Can you please share any valuable pointers?

Thanks

lljotall commented 7 years ago

I wanted to plot a 7-set Chow Ruskey and got the same error. Since I REALLY wanted to get this plot done, I dug into the source code and found where exactly the problem is.

So, the history starts at the paper published by Chow and Ruskey in 2005, proving that you can draw any n-set Venn diagram by splitting the plane in 2^n rays and adjusting the area of each region to the number of elements in the intersection of the sets it represents (link here: http://www.sciencedirect.com/science/article/pii/S1571066105050395). They do that by mentioning Edward's construction for a Venn diagram, in which you interweave curlier and curlier curves to divide the plane in 2^n regions (check figure 5 of the paper to visualize the mechanism). Then, they use this same topology to build their own n-set Venn diagram by associating each region to the node of a graph - if two regions share a border, their corresponding nodes will be linked by an edge. You start your diagram by picking any path that includes the region corresponding to the intersection of all sets and goes all the way to the outside of your diagram (that, in theory, corresponding to no set at all).

In the paper, the path the authors use as an example is the path 1234 -> 123 -> 12 -> 1 -> 0, which can be encoded as the regions corresponding to 1111 -> 1110 -> 1100 -> 1000 -> 0000. Here we can see a nice pattern that you can just travel outwards in the regions by dropping the set with highest index. This is exactly what has been implemented in this package, at line 57 of the file R/ChowRuskey.R.

The problem is that this pattern only works until 5 sets. The interweaving of the sixth curve around the circle gets in the middle of regions corresponding to 1234 and 123, and they no longer share a border for complex diagrams - hence, there's no edge between 111100 and 111000. I've added a drawing showing this case for n = 6 (the sets drawing was got from here: https://commons.wikimedia.org/w/index.php?curid=1472309). The regions are numbered accordingly to the sets relative to them - not all regions are numbered for simplicity. Since cutedge is supposed to be the edge that those two nodes share, it's length is zero when the algorithm looks for their intersection.

edawrdvenn6

I tried the path indicated in the image and successfully got a 6-set Venn diagram! I followed the same procedure for a 7-set and managed to make it work with the following initial path:

dualPath <- c("1111111", "1111110", "1111100", "1101100", "1101000", "1100000", "1000000", "0000000")

Maybe there's some pattern that can be followed for all n < 9, but I didn't go after it. A quick fix, though not the best practice, is to add an 'if' checking for the number of sets and choosing an appropriate initial path for the diagram.

Hope this helps to fix the issue so everyone can build crazy Chow Ruskey diagrams and find some cool patterns in the data :]