Questions tagged [gtable]

`gtable` is an R package used to facilitate the layout of graphics based on the grid package.

The R package gtable is designed to help construct and manipulate layouts containing graphical elements. The standard grid package in R provides low-level functions to define viewports, and place graphical elements (grobs) at specific locations within the device window. gtable builds upon these functions and provides a higher-level interface, where one can e.g. merge two layouts, add columns, rows, insert graphical elements in a given cell, and change the display order, among other things.

The gtable package is used internally by ggplot2, and can therefore be used to modify the layout of such plots.

140 questions
6
votes
3 answers

ggplot2 2.1.0 broke my code? Secondary transformed axis now appears incorrectly

Some time ago, I inquired about adding a secondary transformed x-axis in ggplot, and Nate Pope provided the excellent solution described at ggplot2: Adding secondary transformed x-axis on top of plot. That solution worked great for me, and I…
Thomas
  • 2,484
  • 8
  • 30
  • 49
6
votes
4 answers

Arrange common plot width with facetted ggplot 2.0.0 & gridExtra

Since I have updated to ggplot2 2.0.0, I cannot arrange charts propperly using gridExtra. The issue is that the faceted charts will get compressed while other will expand. The widths are basically messed up. I want to arrange them similar to the…
Jordi Vidal
  • 439
  • 1
  • 6
  • 10
6
votes
1 answer

How to set legend height to be the same as the height of the plot area?

I have arranged two plots: a line chart on top and a heatmap below. I want the heatmap legend to have the same height as the plot area of the heatmap, i.e. the same length as the y-axis. I know that I can change the height and size of the legend…
5
votes
2 answers

Vertically align faceted ggplots of different heights when using coord_equal()

I am trying to combine two FACETED ggplot objects with coord_equal() using cowplot::plot_grid() or egg::ggarrange() and vertically align them. The egg::ggarrange() approach works fine for UNFACETED plots, with the solution posted here. However, the…
Kevin
  • 491
  • 3
  • 10
5
votes
2 answers

ggplot grobs align with tableGrob

I'm having difficulty to find solution for aligning ggplot grob and table grob. I tried to follow the instruction here but still didn't give the results I wanted. library(grid) library(gridExtra) library(ggplot2) library(tibble) library(gtable) dat…
yuskam
  • 310
  • 3
  • 8
5
votes
3 answers

Arrange ggplot plots (grobs with same widths) using gtable to create 2x2 layout

I am attempting to use grobs and gtable to arrange 4 (ggplot2) plots into a 2x2 grid. I don't know how to set widths, and also a non- 1xn, or nx1 arrangement. Using this code: data(iris) a <- ggplot(iris, aes(x=Species, y=Petal.Width)) +…
nofunsally
  • 2,051
  • 6
  • 35
  • 53
5
votes
1 answer

Changing height of strip text background in ggplot2 does not work as expected

###Load libraries library(ggplot2) library(gtable) ###Build plot d <- ggplot(mtcars, aes(x=gear)) + geom_bar(aes(y=gear), stat="identity", position="dodge") + facet_wrap(~cyl) ###Change height of strip text g <-…
shekeine
  • 1,445
  • 10
  • 22
5
votes
1 answer

R: ggplot2 make two geom_tile plots have equal height

I have two ggplot geom_tile plots that I put together using grid.arrange() from the gridExtra library. This is the result library(ggplot2) library(plyr) p3 <- ggplot2(...) p4 <- ggplot2(...) grid.arrange(p3, p4, ncol=2) I would like to get it so…
yoda230
  • 449
  • 6
  • 14
5
votes
2 answers

Juxtapose tableGrob with ggplot2 y-axis

Is there an elegant way to align the tableGrob rows with the axis breaks? I would like to juxtapose a tableGrob and ggplot chart in R (I need to reproduce some SAS output used in previous versions of a public report). Like this minimal reproducible…
penguinv22
  • 349
  • 5
  • 12
5
votes
1 answer

gtable structure element description

If I create a gtable and look at some of the elements, I see for instance: test<-data.frame(x=1:20, y=21:40, facet.a=rep(c(1,2),10), facet.b=rep(c(1,2), each=20)) p <- qplot(data=test, x=x, y=y, facets=facet.b~facet.a) # get gtable object z <-…
4
votes
1 answer

Adjusting font size within a grob using textGrob() and ggplot2

I am trying to increase the fontsize for a second axis title added as a grob (for reasons that will become apparent). Here is some toy data to graph library(Hmisc) library(dplyr) # Plot power vs. n for various odds ratios (n <- seq(10, 1000,…
llewmills
  • 2,959
  • 3
  • 31
  • 58
4
votes
1 answer

Customize label element position in ggplot using gtable/grob

I am creating GIS maps for DC using ggplot in R. I am trying to customize my legend bar and labels. I can move legend keys but not the label using gtable_filter. I would like to move the last label '1' near it's legend bar like other labels. Any…
Deepak
  • 55
  • 6
4
votes
0 answers

How do I "cross" a cell in a table without names

When I try to adapt the example from the vignette to gridExtra, namely g <- tableGrob(iris[1:4, 1:3]) g <- gtable_add_grob(g, grobs = grobTree( segmentsGrob( # diagonal line ul -> lr x0 = unit(0,"npc"), …
Karsten W.
  • 17,826
  • 11
  • 69
  • 103
4
votes
1 answer

Setting width in gtable object collapses plot; this used to work but it doesn't anymore.

The following code used to work but doesn't anymore. Does anybody have an idea what's going on? It must be some change in the underlying gtable code. require(cowplot) # for plot_grid() require(grid) # for unit_max() # make two plots plot.iris <-…
Claus Wilke
  • 16,992
  • 7
  • 53
  • 104
4
votes
2 answers

Title getting cut off using grid.arrange

I built a function for quickly plotting a table with a lot of help from this answer from @baptiste. plotTable<-function(data, title=NULL, footnote=NULL, fontsize=9, plotIt=TRUE, show.rownames=TRUE){ # Generic method to plot tabular data # Built…
Ben
  • 20,038
  • 30
  • 112
  • 189
1 2
3
9 10