rpdfggplot2do.call

corrupted pdf file in pdf() in R when using ggarrange and do.call


I am trying to create a pdf output using

pdf("summary3.pdf",onefile=TRUE)
do.call(ggarrange, c(graphsList, list(ncol = 2, nrow=3, rremove("x.text"), align="hv" ) ))
dev.off

The graphsList is a collection of qplot objects derived from looping through this

emo_plot[[cor]] <- qplot(sentiment, xlab="Essay emotions", data=td_emo, weight=count, geom="bar",fill=sentiment)+ggtitle(pdfNames[cor])

The summary.pdf that is generated is corrupt and cannot be opened. I read

That I need to have a print statement. I tried that with

f <- function(x){print(ggarrange(x))}
pdf("summary3.pdf",onefile=TRUE)
do.call(f, c(graphsList, list(ncol = 2, nrow=3, rremove("x.text"), align="hv" ) ))
dev.off

But I get the error

Error in (function (x)  : 
unused arguments (list(list(c("negative", "positive")

Also, when trying to do dev.off I get this

dev.off
function (which = dev.cur()) 
{
if (which == 1) 
stop("cannot shut down device 1 (the null device)")
.External(C_devoff, as.integer(which))
dev.cur()
}
<bytecode: 0x0000021967e8fc50>
<environment: namespace:grDevices>

Does anyone have a solution?


Solution

  • pdf("summary3.pdf",onefile=TRUE)
    do.call(ggarrange, c(graphsList, list(ncol = 2, nrow=3, rremove("x.text"), align="hv")))
    dev.off()