Hi Jerry!
I haven't used this package yet, but it seems there is no out-of-the-box solution for what you ask.
However, there is in fact a hack-ish solution to this, using the plot object that the ggVennDiagram
function returns:
library(ggVennDiagram)
t1<-c(1,1,0,1,1,1,1,0,1,0)
t2<-c(0,1,0,1,0,1,0,1,1,0)
t3<-c(1,1,1,1,1,1,0,0,1,0)
plt <- ggVennDiagram(apply(cbind(t1, t2, t3), 2, function(x) which(x == 1)))
# Show the plot with label with zeros.
plt
# I found that the label data is stored in the object, so we can filter out the zeros.
remove_zero_labels <- function(layer) {
if(layer$constructor$data == "region_label") {
layer$data <- layer$data[layer$data$count != 0, ]
}
return(layer)
}
# Apply the function to the plt object (2 options)
# base R.
lapply(plt$layers, remove_zero_labels)
# Nicer approach because it does not return anything. Requires {purrr} package.
purrr::walk(plt$layers, remove_zero_labels)
# Show the plot **without** label with zeros.
plt
Hope this helps
Cheers!
This post was published by an Appsilon team member. Our company can help you get the most out of RShiny and Posit/RStudio products.
Check our open positions here.
Appsilon: Building impactful RShiny Dashboards and providing R coding services.