Wrong colors for Venn diagram when the area of one circle is 0

340 views Asked by At

Why the color changes when the area of one circle is 0 ("A" = 0) compared to if it is 0.1 ("A" = 0.1) --> compare example 1 and 2. Also if A and B is 0, the circle is black instead of green (see example 3)..

library(eulerr)

# example 1
fit <- euler(c("A" = 0.1, "B" =  10, "A&B" = 5))
p1 <- plot(fit,
          fills = list(fill = c("black", "blue", "green")),
          labels = F)
p1

enter image description here

# example 2
fit <- euler(c("A" = 0, "B" =  10, "A&B" = 5))
p2 <- plot(fit,
          fills = list(fill = c("black", "blue", "green")),
          labels = F)
p2 

enter image description here

# example 3
fit <- euler(c("A" = 0, "B" =  0, "A&B" = 5))
p3 <- plot(fit,
           fills = list(fill = c("black", "blue", "green")),
           labels = F)
p3

enter image description here

Edit:

I have found a work around with this here (see below). But the order of the colors seems to behave very weird. A is supposed to be black, B --> blue and A&B --> green. If none is 0 this is the correct order --> c("black", "blue", "green"). But if either A or B is 0 then the order is different, basically just how they appear from left to right in the graph. weird....

combo <- c(A=1, B = 10, "A&B" = 1)
fit <- euler(combo)



p <- plot(fit,
          fills = list(fill = 
                         if (combo["A"] == 0) {
                           c("green", "blue")
                           
                         } else if (combo["B"] == 0)  {
                           c("black", "green")
                         } else {
                           c("black", "blue", "green")
                         }
          ),
          labels = F)

p
2

There are 2 answers

4
stlba On

The colours are being used in order. If A=0 then there is nothing to fill for A, so the area for B is filled with the first colour (black), and the area for A&B with the second colour (blue). In the third example, A and B both have no fill so A&B is filled with the first colour instead.

The simplest solution is just to remove a colour (or multiple) from the vector if you have a value of 0. Eg.

# example 2
fit <- euler(c("A" = 0, "B" =  10, "A&B" = 5))
p2 <- plot(fit,
          fills = list(fill = c("blue", "green")),
          labels = F)
0
zx8754 On

Edit: Re-reading your post, eulerr is working as expected.

  • p1 - A is black, B is blue, AB overlap is green
  • p2 - A is black, B is blue, there is no green as A is fully inside B, so it is just black
  • p3 - A is black, B is blue, but as A and B fully overlap, A is fully on top of B, so it is all black.

Maybe use transparency, as below:

fit <- euler(c("A" = 0, "B" =  0, "A&B" = 5))
p3 <- plot(fit, fills = list(fill = c("black", "blue", "green"), alpha = 0.4),
           legend = list(side = "right"))
p3

enter image description here


Original answer, still relevant to understand overlap colours...

Number of colours should match number of sets, in this case we only have 2 sets: A and B, so we only need 2 colours, overlap colours are generated by "blending" overlapping set colours, see:

# R version 4.0.2
# eulerr_6.1.0
library(eulerr) 

fit <- euler(c("A" = 1, "B" =  10, "A&B" = 5))
plot(fit, fills = list(fill = c("red", "green")), legend = list(side = "right"))

enter image description here

fit <- euler(c("A" = 0, "B" =  10, "A&B" = 5))
plot(fit, fills = list(fill = c("red", "green")), legend = list(side = "right"))

enter image description here