0

Hi there are several ways to convert R base plots to grob object, however I can't seem to get venn diagrams from the VennDiagram package to do this. I tried two different methods but both failed. Any ideas? thanks!

library ( VennDiagram )
library(ggplotify)
library(gridGraphics)

venn.plot <- draw.pairwise.venn(
    area1 = 100,
    area2 = 70,
    cross.area = 30,
    category = c("First", "Second"),
    cat.pos = c(0, 180),
    euler.d = TRUE,
    sep.dist = 0.03,
    rotation.degree = 45
);




grab_grob <- function(){
    grid.echo()
    grid.grab()
}

grid.draw(venn.plot )
g <- grab_grob()
p1 <- as.grob( venn.plot )
Ahdee
  • 4,679
  • 4
  • 34
  • 58

1 Answers1

2

Your venn.plot object is a gList, a list of grobs. You can use that object directly. If you want p1 with class grob, you can substitute the last line with:

> p1 <- grobTree(venn.plot)

Then,

> is.grob(p1)
[1] TRUE
> class(p1)
[1] "gTree" "grob"  "gDesc"
vqf
  • 2,600
  • 10
  • 16
  • thanks this is perfect. Just in case someone else is reading. I can go one step further and convert this to a ggplot object `as.ggplot(p1) + ggtitle ("gtitle")` – Ahdee May 31 '19 at 16:06