0
votes

I struggling to draw a simple Venn diagram, and I'm getting errors that I do not understand.

I cannot work out what is wrong in my codes (below) compared to the one written in the Rdocumentation for the draw.triple.venn diagram function - the code is fine in my opinion (https://www.rdocumentation.org/packages/VennDiagram/versions/1.6.20/topics/draw.triple.venn).

library(VennDiagram)
library(gridExtra)

body(draw.triple.venn)[[78]] <- substitute(cell.labels <- paste0(areas," : ", round( 100*areas/sum(areas), 1), "%"))
# this line of code adds %s to each of the cells in the Venn Diagram

g <- draw.triple.venn(
    area1 = 2951, 
    area2 = 2764, 
    area3 = 2764,
    n12 = 719, 
    n23 = 807, 
    n13 = 1034, 
    n123 = 325,
    category = c("Mental Health", "Community", "Social Care"),
    fill = c("blue", "red", "green"), 
    cat.col = c("blue", "red", "green"), 
    lty = "blank",
    euler.d = TRUE, 
    scaled = TRUE, 
    cex = 2, 
    cat.cex = 2);

grid.arrange(gTree(children = g), main = "Breakdown of WSIC Service Users", sub = "By table")

The error message that I get, and cannot work out what it means is:

Error in if (max.x - min.x >= max.y - min.y) { : 
 missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In sqrt(r1^2 - (l.x.cept.13 - x.centres[1])^2) : NaNs produced
2: In sqrt(r1^2 - (l.x.cept.13 - x.centres[1])^2) : NaNs produced

Thank you!

1
Try it again in a new R session. I got the same error when I tried this, but they went away when I used a new R session. It's probably some namespace collision with another package that I had loadeddivibisan
The error message unfortunately remains. I've also tried downloading the newest version of R. I wonder if you don't mind sharing the output with me?Dani

1 Answers

1
votes

There is a reported bug with this issue here. I have tried to reproduce the example and I get the same error. If you are willing to try my nVennR library, you can get the diagram like this:

library(nVennR)
myV <- createVennObj(nSets = 3, sNames = c("Mental Health", "Community", "Social Care"), sSizes = c(0, 598, 913, 807, 873, 1034, 719, 325))
myV <- plotVenn(nVennObj = myV, borderWidth = 2, setColors = c('blue', 'red', 'green'))

The result is an SVG file: Triple Venn diagram

There are some visualization parameters, as you can see in the vignette. There, you can also find the rationale for the numbers in sSizes. There are other modes of data entry. The easiest way is to provide a list of lists with the elements of each set (you can see one example at the beginning of the vignette). The package will calculate all the regions in the diagram for you, and then you can query the elements belonging to each region.