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
112
votes
9 answers

Left align two graph edges (ggplot)

I'm using ggplot and have two graphs that I want to display on top of each other. I used grid.arrange from gridExtra to stack them. The problem is I want the left edges of the graphs to align as well as the right edges regardless of axis labels. …
Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519
33
votes
2 answers

How to use facets with a dual y-axis ggplot

I have been trying to extend my scenario from here to make use of facets (specifically facet_grid()). I have seen this example, however I can't seem to get it to work for my geom_bar() and geom_point() combo. I attempted to use the code from the…
Dan
  • 2,625
  • 5
  • 27
  • 42
27
votes
5 answers

Save plot with a given aspect ratio

I'm working with the really awesome library ggplot2. I figured out how to set the aspect ratio of a plot by using coord_fixed. Now, I'd like to save the plot to a PDF with a specified width (e.g 10 cm) and let required height get calculated. I did…
marsl
  • 959
  • 1
  • 14
  • 25
22
votes
5 answers

Multiple ggplots of different sizes

It's relatively simple using grid.arrange in the gridExtra package to arrange multiple plots in a matrix, but how can you arrange plots (the ones I'm working on are from ggplot2) when some plots are intended to be larger than others? In base, I can…
Hugh
  • 15,521
  • 12
  • 57
  • 100
22
votes
2 answers

Force X axis text on for all facets of a facet_grid plot

I have the same problem as this user: I'd like to make a facet_grid plot with a discrete x-axis, and I'd like to have the x-axis labels be written under each facet rather than only underneath the bottom row of facets. For instance: # Drop some…
Drew Steen
  • 16,045
  • 12
  • 62
  • 90
20
votes
3 answers

Center-align legend title and legend keys in ggplot2 for long legend titles

I am having a hard time making the title of a legend center-aligned relative to the legend keys when the legend title is long. There is a question from a year ago that works for short titles, but it doesn't seem to work for long ones. Example, first…
Claus Wilke
  • 16,992
  • 7
  • 53
  • 104
19
votes
1 answer

Annotating facet title as strip over facet

I want to add a facet title as strip over a facetted plot in ggplot2. My MWE throws an error. library(ggplot2) library(gtable) p <- ggplot(mtcars, aes(mpg, wt)) + geom_point() p <- p + facet_grid(. ~ cyl) # get gtable object Plot1 <-…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
18
votes
2 answers

Align ggplot2 plots vertically

With the code found at https://gist.github.com/low-decarie/5886616 A dual dendodogram tile plot can be produced: dual_dendogram_tile_plot(as.matrix(USArrests), main="USA Arrests") The problem: Align the vertical dendogram with the tile plot…
Etienne Low-Décarie
  • 13,063
  • 17
  • 65
  • 87
17
votes
2 answers

Seeking workaround for gtable_add_grob code broken by ggplot 2.2.0

In plots with multiple facet variables, ggplot2 repeats the facet label for the "outer" variable, rather than having a single spanning facet strip across all the levels of the "inner" variable. I have some code that I've been using to cover the…
eipi10
  • 91,525
  • 24
  • 209
  • 285
17
votes
1 answer

The perils of aligning plots in ggplot

QUESTION How do you combine separate plots (ggplot2), with different y-axis and different plot heights, yet retain alignment? DETAIL When combining plots with grid.arrange (method1), with different y-axis units, they do not align. One way around…
wab
  • 797
  • 6
  • 19
12
votes
3 answers

Remove some of the axis labels in ggplot faceted plots

I have created a plot like the one here with ggplot2 package and facet_wrap function, and I would like to suppress some of the x-axis text to make it more legible. For example, here it would be more legible if the x-axis scales appeared only on…
Pop
  • 12,135
  • 5
  • 55
  • 68
12
votes
3 answers

aligning distinct non-facet plots in ggplot2 using Rpy2 in Python

I am combining two distinct plots into a grid layout with grid as suggested by @lgautier in rpy2 using python. The top plot is a density and and the bottom a bar graph: iris = r('iris') import pandas # define layout lt = grid.layout(2, 1) vp =…
user248237
11
votes
2 answers

Draw Lines between Facets of facet_grid

Intro I want to draw lines between a faceted ggplot. The main goal is to connect those measurements with a line which we want to test against. So basically I want to insert some kind of significance bars inside and between the facets of a ggplot…
TMC
  • 75
  • 10
11
votes
1 answer

ggplot geom_point: how to set font of custom plotting symbols?

With ggplot::geom_point we are able to set any character for plotting symbols using scale_shape_manual. I am coming with an example which demonstrates the purpose: use triangles to make a heatmap with two values in each cell: require(ggplot2) data…
deeenes
  • 4,148
  • 5
  • 43
  • 59
10
votes
2 answers

ggplot2: Using gtable to move strip labels to top of panel for facet_grid

I am creating a graphic using facet_grid to facet a categorical variable on the y-axis. I decided not to use facet_wrap because I need space = 'free' and labeller = label_parsed. My labels are long and I have a legend on the right so I would like to…
Tom Harrop
  • 678
  • 2
  • 7
  • 23
1
2 3
9 10