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
?
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.
The base R functions such as par() and layout() will not work with ggplot2 because it uses a different graphics system and this system does not recognize base R functionality for plotting. However, there are multiple ways you can combine plots from ggplot2 . One way is using the cowplot package.
gtable is a layout engine built on top of the grid package. It is used to abstract away the creation of (potentially nested) grids of viewports into which graphic objects can be placed. gtable makes it easy to ensure alignment of graphic elements and piecemeal compositions of complex graphics.
Creating a Grid of Plots To do this, you use the parameter value mfrow=c(x,y) where x is the number of rows that you wish to have in your plot and y is the number of columns. When you plot, R will place each plot, in order by row within the grid that you define using mfrow .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With