Search code examples
gridr-markdownvenn-diagram

How do I get grid.draw to render in a RMarkdown chunk?


I am trying to include a venndiagram in my Rmarkdown report. In order to return the object itself filename is set to NULL; the figure has then to be rendered using grid.draw(). When I do this in the console the figure displays just fine; when I do it in the code chunk nothing is returned in line. How do you get grid.draw to return a image in line from an Rmarkdown code chunk?

The following code is in one of the code chunks:

require(VennDiagram)

list1<-c("A", "B", "C", "D")
list2<-c("B", "D", "E")
list3<-c("A", "D", "Z")

p<-venn.diagram(
x=list( list1, list2, list3),
category.names= c("list1", "list2", "list3"),
filename= NULL
)


grid.draw(p)



Solution

  • What output format are you using? might worth updating your R/Rstudio programs as well. When I run this in a plain Rmarkdown file, I get what I assume is the desired output. I always try to output to HTML, and then print the HTML document to a .PDF from the web browser if needed to retain as much HTML formatting as possible

    ---
    title: "Untitled"
    author: "Author"
    date: "10/13/2021"
    output: html_document
    ---
    
    ```{r}
    library(VennDiagram)
    
    list1<-c("A", "B", "C", "D")
    list2<-c("B", "D", "E")
    list3<-c("A", "D", "Z")
    
    p<-venn.diagram(
    x=list( list1, list2, list3),
    category.names= c("list1", "list2", "list3"),
    filename= NULL
    )
    
    grid.draw(p)
    ```
    

    enter image description here