grid.arrange() and ggsave()

Showing 1-5 of 5 messages
grid.arrange() and ggsave() alobo 4/20/11 11:38 AM
When I use ggsave() after grid.arrange(), i.e.
> grid.arrange(sgcir1,sgcir2,sgcir3,ncol=2,nrow=2)
> ggsave("sgcirNIR.jpg")

I do not save the grid plot but the last individual ggplot. Is there any
way of actually saving the plot as displayed by grid.arrange using
ggsave() or something similar?
(besides using the older way
> jpeg("sgcirNIR.jpg")
> grid.arrange(sgcir1,sgcir2,sgcir3,ncol=2,nrow=2)



Re: grid.arrange() and ggsave() Brandon Hurr 4/20/11 12:06 PM
I believe that it has to be done the "older way" since you're actually plotting multiple ggplot objects simultaneously and not one large object with multiple components (acceptable input for ggsave). 

I'd love for someone to correct me. 


You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example:

To post: email
To unsubscribe: email
More options:

Re: grid.arrange() and ggsave() baptiste auguie 4/20/11 1:47 PM
The following should work with a recent version of gridExtra (>=0.8 I think).

p <- arrangeGrob(qplot(1,1), textGrob("test"))
grid.draw(p) # interactive device

ggsave("saving.pdf", p) # need to specify what to save explicitely

I could add the following line to grid.arrange,$set(arrangeGrob(...))

so that last_plot() returns the collection of grid objects and your
initial attempt would work, but it seems wrong to me; last_plot()
should probably only return the last ggplot, nothing else. I'm happy
to be convinced otherwise though.



Re: grid.arrange() and ggsave() alobo 4/28/11 12:17 AM
You are probably right, but then we would perhaps need another function
(i.e., ggridsave()) to save what we have in the graphic window as it is in one
single command:
> grid.arrange(sgcir1,sgcir2,sgcir3,ncol=2,nrow=2)
> ggridsave("sgcirNIR.jpg")


2011/4/20 baptiste auguie <>:

Re: grid.arrange() and ggsave() baptiste auguie 4/28/11 1:39 AM
Doing so would mean that gridExtra would replicate the code in ggsave
and last_plot with very minor changes, which is never good. I would
argue that a better solution would be to extract the part of ggsave
that isn't specific to ggplot2 and place it in a more generic package
that could be accessed by all grid-related packages. Not sure where
though, since R-base probably wouldn't want the burden, and ggplot2
would require it as a dependency.