Is there a way to change background color or color the inverse of the input sets?

476 views Asked by At

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

1

There are 1 answers

1
zx8754 On BEST ANSWER

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