Closed Dahaniel closed 9 years ago
There are two separate issues:
1- print()
used to draw the results of arrangeGrob()
, which was a design decision (reluctantly) inherited from lattice and ggplot2. The conventional way of displaying grid-based graphics is grid.draw()
, and that's what gtable uses. So if you saved a grob g
, and want to display it, use grid.draw(g)
(possibly after grid.newpage()
if you want a blank page below. Incidentally, ggplot2
recently gained a grid.draw
method (in the dev version), so this will eventually get a bit more consistent.
BTW, plot(g)
will produce some output, but meant for debugging only; you really want to use grid.draw()
.
2- ggsave()
does some checking that the plot object is of class ggplot
, which prevents its use for other grobs. arrangeGrob
used to trick it with a fake "ggplot" class, but it wasn't a good strategy. Instead, I've finally convinced Hadley to remove the class check in ggsave, which you can get in the dev version of ggplot2.
Okay great, thanks for that explanation, will change my function!
Hi there, I just updated to gridExtra 2.0 and found some major changes to how it behaves and this affects the bahaviour of the functions I am using it in. Maybe you have some advice on how I could restore the "old behaviour".
e.g. using your grid.arrange example with arrangeGrob:
old behaviour:
when I woul call
arrangeGrob(t, p, p2, r, ncol=2)
from within a function it would display the plot or if I would assign the functions output to a variable (p <- myfunction()
), the plot would be stored there and I could e.g. save the plot viaggsave(plot = p, file = p.pdf)
new behaviour:
when using
p <- arrangeGrob(t, p, p2, r, ncol=2)
and then executingp
it returns:I can however return the plot from the function with
plot(p)
but I cannot redirect this output to a variable that executes the plot automatically anymore. Alsoggsave()
gives me an error:Error in ggsave(plot = a, "a.pdf") : plot should be a ggplot2 plot
Is there a workaround to get back to the old behaviour somehow? I have to admit that I am not really experienced with
gtable
etc., that's why I lovegridExtra
so much ;)Thanks in advance, Daniel