Skip to content
ferroao edited this page Mar 8, 2017 · 16 revisions

Welcome to the gridextra wiki!

Features implemented

tableGrob: display graphical tables with grid graphics

arrangeGrob: arrange multiple grid graphics on a page

ngonGrob: draw regular polygons and ellipses

Relation to grid, gtable, and ggplot2

Historically, gridExtra was based directly on grid, but from v>=2.0.0, I decided to switch to gtable which offers very convenient and flexible layouts at a higher level. Naturally, gtable is itself built on grid, so the two remain compatible. Importing gtable also let me experiment with improvements for gtable functions, without compromising other packages that depend on gtable, e.g. ggplot2. Since ggplot2 uses gtable for its internal layout, gridExtra can help arrange multiple ggplots, like any other grid-based graphics.

FAQ

Problems with arrangeGrob

print(arrangeGrob(p)) used to plot, now it just prints some information about the gtable. What happened, and what should I do?

print() used to draw the results of arrangeGrob(), which was a design decision (reluctantly) inherited from lattice and ggplot2. The conventional way of displaying grid-based graphics is grid.draw(), and that's what gtable uses. So if you saved a grob g, and want to display it, use grid.draw(g) (possibly after grid.newpage() if you want a blank page below. Incidentally, ggplot2 recently gained a grid.draw method, so this has eventually become a bit more consistent.

BTW, plot(g) will produce some output, but meant for debugging only; you really want to use grid.draw().

Problems with ggsave

I used ggsave() from ggplot2 to save the grobs returned by arrangeGrob(), now it fails. What happened, and what should I do?

Earlier versions of ggplot2::ggsave() did some checking that the plot object was of class ggplot, which prevented its use for other grobs. arrangeGrob used to trick it with a fake "ggplot" class, but it wasn't a good strategy. Hadley removed the class check in ggsave in more recent versions of ggplot2, so if you encounter this issue please update your packages.

Problems with Rstudio

marrangeGrob doesn't seem to work with Rstudio.

There was a problem calling dev.new with Rstudio's built-in graphics device, it's now fixed

Problems with Shiny

Shiny's renderPlot() doesn't render my plots with grid.arrange

Link to a suggested workaround

workaround in answer

Problems with grid.table()

The table doesn't fit on the page

Two options:

  1. resize the content
  2. split the table into multiple pages

Old functions removed from the package

Initially, gridExtra included more grob functions, largely experimental: borderGrob (rectangular borders of type "L", "U", etc.), barbedGrob (points and lines inspired by type="b" in base graphics), stextGrob (text with shadow border), patternGrob (fill patterns for rectangles), etc.. With the more recent update, I removed these from the codebase, in an attempt to clean up the package and simplify maintenance. Here's a link to the last commit before those functions were removed.

The new version of gridExtra broke my code, I want the old one back

Consider browsing the package vignettes and this wiki page to see if the new system could work for you; in my opinion the code has much improved, albeit with some important changes in user interface. If you cannot find a way to use the newer version, e.g. because your code relies on experimental grobs that have been removed from the package, you can

Clone this wiki locally