rvenn-diagrameulerr

How to change the label position when plotting venn diagram from eulerr package in R?


I am trying to create a scaled venn diagram using the eulerr package in R.

My Code is below:

plot(euler(c( "LUTS"=98, "Symptoms of UTI"=46, "Positive urine culture"=39, 
              "Symptoms of UTI&LUTS"=33, "LUTS&Positive urine culture"=24, 
              "Symptoms of UTI&Positive urine culture"=22, "Symptoms of UTI&LUTS&Positive urine culture"=18),
           input = "union", shape = "ellipse"), key = TRUE, counts = TRUE, 
     quantities = list(type = c("counts", "percent"), font=3, round=2, cex=0.8), 
     fills =list(fill=c(viridis::plasma(n = 3))), alpha = 0.3, c("#1957FF", "#FF750C", "#FF220C"), alpha = 0.3, 
     edges=list(lty = 1), factor_names = TRUE, labels=list(font=2, cex=1), legend = FALSE)

The output: enter image description here

How do I get the percent values to print below the count values? Something like this:

enter image description here


Solution

  • Unless I'm missing something in the docs, I don't see the option to do this. However, since plot.euler produces a grob tree, we can edit the output with a bit of grob-hacking:

    library(eulerr)
    
    v <- plot(euler(c( "LUTS"=98, "Symptoms of UTI"=46, "Positive urine culture"=39, 
                  "Symptoms of UTI&LUTS"=33, "LUTS&Positive urine culture"=24, 
                  "Symptoms of UTI&Positive urine culture"=22, 
                  "Symptoms of UTI&LUTS&Positive urine culture"=18),
               input = "union", shape = "ellipse"), key = TRUE, counts = TRUE, 
         quantities = list(type = c("counts", "percent"), font=3, round=2, cex=0.8), 
         fills =list(fill=c(viridis::plasma(n = 3))), alpha = 0.3, 
         c("#1957FF", "#FF750C", "#FF220C"), alpha = 0.3, 
         edges=list(lty = 1), factor_names = TRUE, labels=list(font=2, cex=1), 
         legend = FALSE)
    
    tags <- v$children[[1]]$children[[1]]$children$tags$children
    
    tags <- do.call(grid::gList, lapply(tags, function(x) {
      x$children[[2]]$label <- sub(" \\(", "\n(", x$children[[2]]$label)
      x$children[[2]]$just <- NULL
      x$children[[2]]$hjust <- 0.5
      x$children[[2]]$vjust <- 1
      x}))
    
    v$children[[1]]$children[[1]]$children$tags$children <- tags
    
    v
    

    enter image description here