-
Notifications
You must be signed in to change notification settings - Fork 4
Home
Welcome to the gridextra wiki!
tableGrob: display graphical tables with grid graphics
arrangeGrob: arrange multiple grid graphics on a page
ngonGrob: draw regular polygons and ellipses
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.
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()
.
I used
ggsave()
fromggplot2
to save the grobs returned byarrangeGrob()
, 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.
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
Shiny's
renderPlot()
doesn't render my plots withgrid.arrange
Link to a suggested workaround
The table doesn't fit on the page
Two options:
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.
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
-
install an older version of gridExtra, available on CRAN archives
-
browse the commit history for an older version of the code, and grab the function that you need. Feel free to include it in your own package if necessary.