Error when trying to create Venn diagrams in R using VennDiagram package

2.3k views Asked by At

I have downloaded and can successfully load the VennDiagram package in R. I'm currently just trying to generate some sample diagrams using this package with the example code provided by the authors of this package. However, for any of the example code that I attempt to use, no graphic is generated, and the only screen output is:

[1] 1

I located the following informative thread: Problems with VennDiagram?

...but the first suggested troubleshooting step, to confirm that we can draw the plot onscreen by assigning the call to venn.diagram() to a temporary variable and then calling grid.draw(temp) [full code shown below], results in the error message

Error in UseMethod("grid.draw") : 
  no applicable method for 'grid.draw' applied to an object of class "c('double', 'numeric')"

My test code is:

library(VennDiagram);
library(grid);

temp <- venn.diagram(
    x = list(
        A = 1:100,
        B = 1:10
        ),
    filename = "2-2_special_case_pairwise-inclusion.tiff",
    cex = 2.5,
    cat.cex = 2.5,
    cat.pos = 0
    );

grid.draw(temp)

Other threads that address this error message suggest that the arguments to grid.draw() should be modified, but I'm not sure why the example above would have been suggested and accepted if it didn't work, and the grid.draw documentation (https://www.rdocumentation.org/packages/grid/versions/3.4.1/topics/grid.draw) doesn't seem to suggest that modification is required.

The above issues apply to all of the examples provided by the authors of this package, so this is not a problem with one particular call to venn.diagram().

Thanks in advance for any advice that you might have.

1

There are 1 answers

0
Hack-R On BEST ANSWER

temp is numeric in your example because you're just creating a file on your filesystem and getting a 1 back to let you know that it worked.

Instead of giving grid.draw the number 1, let's give it something to draw :)

temp <- venn.diagram(
  x = list(
    A = 1:100,
    B = 1:10
  ),
  filename =NULL,
  cex = 2.5,
  cat.cex = 2.5,
  cat.pos = 0
);


grid.draw(temp)

enter image description here