18

docs.ggplot2.org currently offers very little documentation for the function ggplotGrob. The EPFL website is a little bit more informative but it is still not very helpful.

Can you please provide a short tutorial on what one can do with the function ggplotGrob?

Remi.b
  • 17,389
  • 28
  • 87
  • 168
  • My final goal is to reproduce the graph presented in [this answer](http://stackoverflow.com/questions/11353287/how-do-you-add-a-general-label-to-facets-in-ggplot2/12660057#12660057). The code in the answer is using functions that are deprecated. – Remi.b Mar 01 '16 at 01:35
  • ggplot2 has far more nuanced facet labeling options now. pls see if they can meet your needs first before grobbing. – hrbrmstr Mar 01 '16 at 03:19
  • 1
    btw the "EPFL website" is just a very old version of the documentation, before ggplotGrob was removed and later re-introduced in another form, IIRC. – baptiste Mar 01 '16 at 05:30

1 Answers1

26

ggplotGrob is the same as ggplot_gtable(ggplot_build(x)); it's just a convenience function to save some typing.

The end goal is to convert the ggplot object, which is essentially a list describing how to build the plot, into a gtable, which is a grid graphical object (grob) that can be drawn on a device. So if what you're after is altering the output of ggplotGrob to change the layout or add graphical components to it, you should look into the gtable package.

baptiste
  • 75,767
  • 19
  • 198
  • 294