Discussion:
How to ggsave multi-page pdf?
Peng Yu
2011-11-29 21:55:25 UTC
Permalink
Hi,

pdf() can be used to create a multi-page pdf. But I don't see how to
create one with ggsave. Does anybody know?

#This will generate error
p=qplot(1:10,1:10)
ggsave(list(p,p), file='main.pdf')

#The second command will overwrite the first one
p=qplot(1:10,1:10)
ggsave(p, file='main.pdf')
ggsave(p, file='main.pdf')
--
Regards,
Peng
baptiste auguie
2011-11-29 22:04:16 UTC
Permalink
Hi,

ggsave prints the plot and calls dev.off, so you cannot add anything
to the device afterwards. If you want you may define your own class
with a print method that recursively plots all the elements of the
list, calling grid.newpage between each. You need to make it a
superclass of ggplot to fool ggsave,

p=qplot(1:10,1:10)
l = structure(list(p, p), class=c("gglist", "ggplot"))
print.gglist = function(x, ...) l_ply(x, print.ggplot, ...)
ggsave(l, file='main.pdf')

HTH,

baptiste
Post by Peng Yu
Hi,
pdf() can be used to create a multi-page pdf. But I don't see how to
create one with ggsave. Does anybody know?
#This will generate error
p=qplot(1:10,1:10)
ggsave(list(p,p), file='main.pdf')
#The second command will overwrite the first one
p=qplot(1:10,1:10)
ggsave(p, file='main.pdf')
ggsave(p, file='main.pdf')
--
Regards,
Peng
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
More options: http://groups.google.com/group/ggplot2
Loading...