Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does `ggplotGrob` work? [closed]

Tags:

r

ggplot2

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?

like image 544
Remi.b Avatar asked Mar 01 '16 01:03

Remi.b


People also ask

What is 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.

Does par () work with ggplot?

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.

What is a Gtable?

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.

How do you make a grid on a graph in R?

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 .


1 Answers

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.

like image 81
baptiste Avatar answered Nov 24 '22 16:11

baptiste