Hi,
I wonder whether it would be possible (desirable?) to define a
widthDetails.ggplot2 method (and heightDetails) so that grid knows the
size of the legend object.
Consider the following case,
library(ggplot2)
p <- qplot(data = mtcars, mpg, hp, geom = "point",
colour = cyl)
p1 <- p + opts(legend.position = "none")
p2 <- qplot(data = mtcars, wt, disp, geom = "point",
colour = cyl) + opts(legend.position = "none")
legend <- p + opts(keep = "legend_box")
legend <- ggplotGrob(legend)
top <- ggplotGrob(p1)
bottom <- ggplotGrob(p2)
layout <- grid.layout(nrow = 2, ncol = 1)
gf = grid.frame(name="gf", layout=layout)
grid.place("gf", top, row=1, col=1)
grid.place("gf", bottom, row=2, col=1)
grid.pack("gf", legend, side="right")
The space allocated by grid.pack clearly doesn't understand that only
the legend is to be drawn (in fact, I'm not sure how it infers the
size of a ggplotGrob at all).
All the best,
baptiste