Although this might be a duplicate, I would like to know the solution for my question. I tried to run the code from question Multiple graphs over multiple pages using ggplot but I don't know how the data is strucured and therefore could not run it. I want to plot multiple graphs and print them on multiple pages in a pdf. I tried it with mtcars:
library(ggplot2)
library(reshape2)
library(plyr)
library(gridExtra)
mtcars2 = melt(mtcars, id.vars='mpg')
mtcars2$group[mtcars2$variable %in% c("cyl", "disp", "hp", "drat")] <- "A"
mtcars2$group[mtcars2$variable %in% c("wt", "qsec", "vs", "am")] <- "B"
mtcars2$group[mtcars2$variable %in% c("gear", "cyl")] <- "C"
p = ggplot(mtcars2) +
geom_jitter(aes(value,mpg, colour=variable)) +
geom_smooth(aes(value,mpg, colour=variable), method="lm", se=FALSE) +
scale_y_continuous(limits = c(0, 60))+
labs(x = "Percentage cover (%)", y = "Number of individuals (N)")
plots = dlply(mtcars2, "group", `%+%`, e1 = p)
ml = do.call(marrangeGrob, c(plots, list(nrow=2, ncol=2)))
ggsave("multipage.pdf", ml)
produces error Error in (function (grobs, ncol, nrow, ..., top = quote(paste("page", : argument "grobs" is missing, with no default
. How do I get this script running?