[R] grid.arrange, grid.layout - legend, global y axis title
bapt4510 at googlemail.com
Tue Nov 15 22:46:19 CET 2011
Please don't cross post.
It seems that ggplotGrob has been replaced by new functions. You can
define it as
ggplotGrob <- function(x) ggplot2:::gtable_gTree(ggplot2:::ggplot_gtable(x))
and it seems to work as before with grid.arrange().
On Wed, Nov 16, 2011 at 3:26 AM, Johannes Radinger <JRadinger at gmx.at> wrote:
> I created several plot with ggplot2 dev mode.
> Now I want to combine the plots in a grid
> e.g. 2x2 with a fixed size of the output.
> What I am doing at the moment is:
> pushViewport(viewport(layout = grid.layout(nrow=2, ncol=2,
> widths = unit(c(7.5,6.5), "cm"),
> heights = unit(rep(5, 2), "cm"))))
> print(plot1, vp = viewport(layout.pos.row = 1, layout.pos.col = 1))
> print(plot2, vp = viewport(layout.pos.row = 1, layout.pos.col = 2))
> print(plot3, vp = viewport(layout.pos.row = 2, layout.pos.col = 1))
> print(plot4, vp = viewport(layout.pos.row = 2, layout.pos.col = 2))
> This is working well so far.
> The y-axis are for all plots the same so I'd like to have a global y-axis title on the left side. How can that be done using my approach?
> I also would like to add a global vertical legend for my plots below all plots.
> The legend should show the to different symbols (same as for the single plots (ggplot2)). I also don't know how to do that.
> I know that there is the function grid.arrange which can do both things but this isn't working because I am in the dev mode of ggplot. Then I get the error: Error: could not find function "ggplotGrob.
> I load my libraries the following way:
> 1) import data
> 2) load library(gridExtra)
> 3) load library(devtools)
> 4) produce plots
> 5) arrange the plots.
> So what is the best way to proceed?
> Should I stay with the grid.layout approach and can I get there a global legend and a global y axis title?
> Or how can I use grid.arrange, define the position of the gobal legend and set the single plot to a fixed size?
> I hope that wasn't to complicated...
> NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
> Jetzt informieren: http://www.gmx.net/de/go/freephone
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
> To post: email ggplot2 at googlegroups.com
> To unsubscribe: email ggplot2+unsubscribe at googlegroups.com
> More options: http://groups.google.com/group/ggplot2
More information about the R-help