I want to create an euler plot inside a function with the eulerr
package:
library(eulerr)
test <- function(listA,listB,file,labels,title){
euler <- euler(list("A"=listA, "B"=listB))
#plot euler object and save to file
pdf(paste0("euler/",file,".pdf"))
plot(euler,
"quantities"=TRUE,
"labels"=labels,
"main"=title)
dev.off()
}
test(c("A","B","C","D"),
c("C","D","E","F","G"),
"test",
c("list A","list B"),
"TITLE")
It runs without an error, but the test.pdf file is empty.
When I run it outside a function I get the plot I wanted:
library(eulerr)
listA <- c("A","B","C","D")
listB <- c("C","D","E","F","G")
labels <- c("list A","list B")
file <- "test"
title <- "TITLE"
euler <- euler(list("A"=listA, "B"=listB))
#plot euler object and save to file
pdf(paste0("euler/",file,".pdf"))
plot(euler,
"quantities"=TRUE,
"labels"=labels,
"main"=title)
dev.off()
I must be missing something really obvious but what am I doing wrong?
You need to add
print()
around your plot. See the R FAQ: