1

I'm working on a shiny app to let students explore the basic probability equations and notation with dynamic Euler (Venn) diagrams responding to changes in probability and displaying the intersection of two sets, the union, the union of one set with the inverse of the other and so on.

So far I find that I can get the closest with eulerr, but I'm hoping to be able to change the background color or otherwise find a way to illustrate sets that include the "background", e.g. the inverse of (A ⋃ B). I could have white represent the selected set for those diagrams, but I'd prefer to be consistent.

I tried using par(bg = 'blue'), but that doesn't appear to have an effect with plot in eulerr, and there doesn't seem to be anything in the documentation.

Am I missing some workaround or parameter, or is this just not possible?

I'd also be happy to use a different package.

Example illustrating A⋂B:

library("eulerr")    
fit <- euler(c("A" = 10, "B" = 5, "A&B" = 3))
plot(fit, fills = c(FALSE, FALSE, TRUE), labels = list(col = "red", font = 4))

enter image description here

Example that would illustrate the inverse of B, if the background color change worked.

fit <- euler(c("A" = 10, "B" = 5, "A&B" = 3))
par(bg = 'blue')
plot(fit,
     fills = c("blue", "white", "white"),
     labels = list(col = "black", font = 4))

enter image description here

zx8754
  • 52,746
  • 12
  • 114
  • 209
naita
  • 13
  • 5
  • Not clear what we trying to do, in the first plot you want intersection A&B to be blue, and in second plot you want as it is shown, so A minus B is blue? If yes, then for the first case use the colours, instead of `fills = c(FALSE, FALSE, TRUE)` try: `fills = c("white", "white", "blue")` ? – zx8754 Oct 07 '20 at 11:35
  • 1
    My bad. I left the par(bg = 'blue') in the first code snippet to illustrate that it didn't do anything. I wouldn't want the background changed there. For the second example I want the background changed as well, to get an illustration like this: https://en.wikipedia.org/wiki/Set_(mathematics)#/media/File:Venn1010.svg Except I coded it for the complement to B and wikipedia shows the complement to A. – naita Oct 07 '20 at 19:21

1 Answers1

0

As the output is a grid object, I'd explore grid library, see example:

library(grid)

# plot, assign to object
x <- plot(fit,
          fills = c("blue", "white", "white"),
          labels = list(col = "black", font = 4), bg = "blue")

# now use grid
grid.newpage()
# background is red
grid.draw(rectGrob(gp = gpar(fill = "red")))
# now add eulerr plot
grid.draw(x)

Or output as png, as it has background argument, here I am setting background to red to illustrate:

png("test.png", bg = "red")

plot(fit,
     fills = c("blue", "white", "white"),
     labels = list(col = "black", font = 4))

dev.off()

Both solutions would output below image:

enter image description here

zx8754
  • 52,746
  • 12
  • 114
  • 209
  • Great! I believe that will get me what I want. I'd started looking into the grid library, but didn't have the experience to quickly find a solution. – naita Oct 07 '20 at 20:57