Need to scale triple VennDiagram using Venndiagram R package

Hi,
I need to generate a triple scaled Venn-diagram using Venndiagram R package. After browsing, I found one answer "mathematically impossible to create a scaled 3-way Venn using circles", However, I still can see scaled triple venn in some publications/presentations. So, could you help me know what is missing in the code below?

grid.newpage()
venn.plot <- draw.triple.venn(area1 = 42, area2 = 17, area3 = 9, n12 = 11, n23 = 5, n13 = 6, n123 = 5,
category = c("P", "ED", "EM"), category.names = c("P", "ED", "EM"), lty = rep("blank", 3), col = rep("black", 3), fill = c("#EFC000FF","#86ab92","#9991aa"), alpha = rep(0.4, 3), cat.pos = c(-40, 40, 360), cat.dist = c(0.05, 0.05, 0.025), cat.fontface = rep("plain", 3), cat.fontfamily = rep("Arial", 3), fontfamily = "plain", fontface = "plain", lwd = rep(2, 3), cat.cex = rep(1, 3), cex = rep(1, 7), resolution = 600, output = TRUE, imagetype="tiff", scaled = TRUE, height = 200, width = 200, units = "px", compression = "lzw", cat.col = c("black", "black", "black"), euler.d = TRUE, overrideTriple = 0, ext.text = FALSE);
grid.arrange(gTree(children = venn.plot), # Add title & subtitle
top = "Group1")

The answer you saw was qualified that it was mathematically possible for only "certain" cases. Looking at {VennDiagram} , scaling for the two-circle case is enabled, but it is disabled for the three-circle case on the grounds that it can result in misleading visualizations. Supposedly there's an argument to override that limitation, but I couldn't find a way to make it work.

draw.tripple.venn()outputs a grid::gList object and it is possible to directly edit those.

library(grid)

# Function to draw a circle with a name
draw_circle <- function(x, y, r, col, name) {
  circleGrob(x = x, y = y, r = r, gp = gpar(fill = col, alpha = 0.5), name = name)
}

# Function to update the radius of a circle in a gTree object
update_circle_radius <- function(gtree, circle_name, new_radius) {
  circle_index <- which(sapply(gtree$children, function(x) x$name) == circle_name)
  gtree$children[[circle_index]]$r <- unit(new_radius, "npc")
  return(gtree)
}

# Create circles for the Venn diagram with names
circle1 <- draw_circle(0.3, 0.5, 0.2, "red", "circle1")
circle2 <- draw_circle(0.5, 0.5, 0.2, "blue", "circle2")
circle3 <- draw_circle(0.4, 0.7, 0.2, "green", "circle3")

# Create a gTree object with the circles
gtree <- gTree(children = gList(circle1, circle2, circle3))

# Draw the gTree object
grid.newpage()
grid.draw(gtree)


# Modify the diameter of the first circle using its name
modified_gtree <- update_circle_radius(gtree, "circle1", 0.3)

# Draw the modified gTree object
grid.newpage()
grid.draw(modified_gtree)

Created on 2023-09-01 with reprex v2.0.2

Unless I had a specific requirement to do this at scale, I can't recommend this approach. For a one-off, I'd write the glist object to a svg file using a driver provided by {svglite} and edit the circles in a GUI vector editor program such as Illustrator.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.