2

I am trying to use the package VennDiagram_1.6.20.

And this is the snippet of code I am using:

library(VennDiagram)
A <- c("AT1G01050", "AT1G01100","AT1G01370","AT1G01510","AT1G01630","AT1G01650","AT1G01820",
   "AT1G01920","AT1G01940","AT1G01960","AT1G02090", "AT1G02100","AT1G02120","AT1G02130",
   "AT1G02140","AT1G02280","AT1G02410","AT1G02500","AT1G02560","AT1G02690","AT1G02740","AT1G02780", 
   "AT1G02840","AT1G03330","AT1G03360","AT1G03860","AT1G03900","AT1G03910","AT1G04080","AT1G04170",
   "AT1G04190","AT1G04250","AT1G04270", "AT1G04410","AT1G04430","AT1G04480","AT1G04510","AT1G04630",
   "AT1G04690","AT1G04710","AT1G04750","AT1G04810","AT1G04820","AT1G04860", "AT1G04870","AT1G04900",
   "AT1G04945","AT1G04980","AT1G05055","AT1G05180")
B <- c("AT1G01050","AT1G01100","AT1G01120","AT1G01370","AT1G01510","AT1G01630","AT1G01650","AT1G01820","AT1G01940","AT1G01960","AT1G02090","AT1G02100","AT1G02140","AT1G02280","AT1G02500","AT1G02560","AT1G02690","AT1G02740","AT1G02780","AT1G02840","AT1G03150","AT1G03330", "AT1G03360","AT1G03860","AT1G03870","AT1G03900","AT1G03910","AT1G04080","AT1G04170","AT1G04190","AT1G04250","AT1G04270","AT1G04410", "AT1G04430","AT1G04480","AT1G04510","AT1G04630","AT1G04690","AT1G04730","AT1G04750","AT1G04810","AT1G04860","AT1G04870","AT1G04900","AT1G04945","AT1G04980","AT1G05055","AT1G05180","AT1G05190","AT1G05210")

ect3_roots_vd <- venn.diagram(
    x = list(A, B),
    filename = "ect3_roots_vd.svg",
    height = 10,
    width = 10,
    resolution = 300,
    imagetype = "svg",
    units = "in",
    category.names = c("roots_ect3" , "roots_te234"),
    print.mode = c("raw", "percent"),
    main="triple vs single mutant roots - ect3",
    main.cex = 2,
    fill = c('#a50026', '#fdae61')
)

Now, when I open the file in Illustrator, this is what I get:

But if I select the file in the Finder and show a preview "clicking" on it with the spacebar the I get the right image that looks like this:

Has anyone else tried saving a venn diagram in svg and had the same problem?

EDIT: I also tried using

ggsave(file="test.svg", plot=ect3_roots_vd, width=10, height=10)

Ant it returns the same result as above: I can see the plot if I "click it" with he space bar but this time, when I open it Ai throws an error and does not even open the file.

My R sessionInfo is:

R version 3.5.2 (2018-12-20)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.3

user20650
  • 24,654
  • 5
  • 56
  • 91
  • Please add the `library` you're loading to use `venn.diagram` function and also some [sample of your data](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – patL Mar 11 '19 at 08:45
  • try with `gridSVG::grid.export` after drawing the plot, also using ``file=NULL` in the plot. – user20650 Mar 11 '19 at 09:05
  • 1
    @patL done, I added both the library and a small example of my lists – Carlotta Porcelli Mar 11 '19 at 13:18
  • @user20650 I added this line: `grid.newpage()` before running the code (same as the one above but with `filename=NULL`) and `grid.export(name="ect3_roots_vd.svg")` right after the plot and now I get the error: _Error in grobToDev.default(gTree, dev) : We shouldn't be here!_ I followed what is suggested here: [https://stackoverflow.com/questions/17255207/error-in-grobtodev-defaultgtree-dev] but didn't manage to fix it. – Carlotta Porcelli Mar 11 '19 at 13:34
  • @CarlottaPorcelli ; re the error, you need to draw the plot ; some reduced code : `library(VennDiagram) ; library(gridSVG) ; ect3_roots_vd <- venn.diagram( x = list(A=A, B=B), filename = NULL) ; grid.draw(ect3_roots_vd); gridSVG::grid.export("so.svg")` – user20650 Mar 11 '19 at 17:42
  • ps . a thought after looking at your image (should of done that first); it looks like the text size is all out of sorts - try removing all the cex, width resolurion etc and see if it improves – user20650 Mar 11 '19 at 17:57
  • @user20650 Firstly, thanks for your inputs. I tried with the grid.draw() and I do see the plot in Rstudio but I can't open the file in Ai, it's says 'unknown error'. I also tried without the cex but if I remove the width and height then the file is empty, all white. At this point I think I will just try a different library (I also wrote to the author of the package in the meanwhile). Thank you very much for your tips ! – Carlotta Porcelli Mar 13 '19 at 08:30
  • you're welcome. sorry I couldn't help. (ps I am not familiar with macOS, so don't know what Ai or illustrator are, but did you try opening the svg file in a browser?) – user20650 Mar 13 '19 at 08:58
  • If i open it in a browser then it works, the problem is that it has been commissioned by "the biologist" that is going to use illustrator to change it a bit :/ otherwise I could have just saved everything in png, for what concerns me – Carlotta Porcelli Mar 13 '19 at 10:00

1 Answers1

3

So, I solved the problem. I set the filename argument to NULL and saved the plot using ggsave and device="svg". Now I can open the file in illustrator and modify it as I prefer.

my_plot <- venn.diagram(x=list(A, B) , 
                          filename = NULL, 
                          fill=c("#283148", "#913535"), 
                          alpha=c(0.8,0.8),
                          euler.d = TRUE,
                          scaled = TRUE,
                          cat.fontfamily = "sans",
                          cat.cex = 1,
                          lwd = c(0.3, 0.3),
                          category.names=c("A", "B"), 
                          #cat.just=list(c(1,-40) , c(0.4,-40)),
                          print.mode = c("raw", "percent"),
                          fontfamily = "sans",
                          main="Overlap between A and B",
                          main.fontfamily = "sans",
                          main.cex = 1,
                          cex = 0.9,
                          width = 10,
                          height = 10,
                          units = "in")

ggsave(my_plot, file="my_plot.svg", device = "svg")
Tapper
  • 1,393
  • 17
  • 28