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
10
votes
1 answer

how to show a legend on dual y-axis ggplot

I am trying to compose a dual y-axis chart using ggplot. Firstly let me say that I am not looking for a discussion on the merits of whether or not it is good practice to do so. I find them to be particularly useful when looking at time based data to…
Dan
  • 2,625
  • 5
  • 27
  • 42
10
votes
2 answers

make panels with same margins when combining ggplot and base graphics

I have generated a figure that combines ggplot and base graphics: t <- c(1:(24*14)) P <- 24 A <- 10 y <- A*sin(2*pi*t/P)+20 #***************************************************************************** par(mfrow = c(2,1)) plot(y,type = "l",xlab…
KatyB
  • 3,920
  • 7
  • 42
  • 72
9
votes
2 answers

How to add lines on combined ggplots, from points on one plot to points on the other?

I need to reproduce plots generated in InDesign in ggplot for reproducibility. In this particular example, I have two plots that are combined into one composite plot (I have used the package {patchwork} for this). I then need to overlay lines…
Megan Beckett
  • 337
  • 1
  • 6
8
votes
2 answers

Overall Label for Facets

Here is some minimal code to generate a graph with two sets of facets. library("ggplot2", quietly = TRUE, warn.conflicts = FALSE) library("RColorBrewer", quietly = TRUE, warn.conflicts = FALSE) val.a <- rnorm(10) val.b <- rnorm(10) val.c <-…
Reuben Mathew
  • 598
  • 4
  • 22
8
votes
2 answers

Align a double line chart and a bar plot on the x axis when both charts have the same X axis. ggplot2

I have been attempting this for quite sometime today and still haven't been able to align two different chart types together by their X axis which are the same. I simply need a double line chart on top of a bar chart when both charts have the same X…
user3720887
  • 719
  • 1
  • 11
  • 18
8
votes
2 answers

grid.layout doesn't like respect and compound units

Using unit.pmax as the default comparison of widths/heights in gtable is proving harder than I'd hoped; after several hours of head scratching I've narrowed it down to this situation: library(grid) w <- list(unit(1,"null"), unit(1,"null")) class(w)…
baptiste
  • 75,767
  • 19
  • 198
  • 294
8
votes
2 answers

ggplot2: Plotting on a grid with fewer plots than viewports

library( ggplot2 ) library( gridExtra ) p1 <- qplot( rnorm( 10 ), rnorm( 10 ) ) p2 <- qplot( rnorm( 10 ), rnorm( 10 ) ) p3 <- qplot( rnorm( 10 ), rnorm( 10 ) ) p4 <- qplot( rnorm( 10 ), rnorm( 10 ) ) p5 <- qplot( rnorm( 10 ), rnorm( 10 )…
polarise
  • 2,303
  • 1
  • 19
  • 28
7
votes
3 answers

Combine multiple facet strips across columns in ggplot2 facet_wrap

I am trying to combine facet strips across two adjacent panels (there is always two adjacent ones with the same first ID variable, but with two different scenarios, let's call them "A" and "B"). I am not particularly wedded to the gtable + grid…
Björn
  • 644
  • 10
  • 23
7
votes
1 answer

Adding sub-tables on each panel of a facet ggplot in r

I am trying to create a complete set of plots using facet_wrap from the ggplot2 package in R. As a simplified example I used a subset of the dataset mpg included in ggplot2 library(plyr) library(ggplot2) library(gtable) library(gridExtra) myData =…
7
votes
1 answer

Transparency in gtable Objects

I am trying to produce png file of ggplot objects with transparent backgrounds. When I was using the ggplot objects directly with panel.background=element_rect(fill = "transparent",colour = NA) I was getting the results I wanted. I am now trying to…
Rob Donnelly
  • 2,256
  • 2
  • 20
  • 29
6
votes
1 answer

How to change one specific facet in ggplot

I created pie charts displaying different scores (0 - 100%) in ggplot with the help of facet_grid(). However the last score is a total score combining the other scores and in order to distinguish it better from the other scores I would like to…
Gilean0709
  • 1,098
  • 6
  • 17
6
votes
1 answer

cbind on ggplotGrob objects fails with "Error in mmm < each : comparison of these types is not implemented"

This appears to be similar to an issue that @baptiste was trying to work around back in 2014. I am revisiting code I wrote back in June that involved creating three ggplotGrobs and combining them with a call to cbind. Now, this code fails with the…
scooteR
  • 185
  • 7
6
votes
1 answer

Add a scale bar and a north arrow outside of the plot area of a facetted map plot

I wish to add a scale bar and a north arrow outside of the plot area of a facetted map plot. As an example, consider the following facetted map plot, as seen in a blog post by Max Marchi (link): # Load the data airports <-…
R. Joe
  • 367
  • 5
  • 13
6
votes
1 answer

Using a font from extrafont in grid.draw

Say I have a dataset like this: dat <- data.frame text = c( "It made me feel very positive to brand X", "It was clear and easy to understand", "I didn't like it al all"), value=runif(3) ) I can plot it in ggplot using can the…
Jacob Curtis
  • 788
  • 1
  • 8
  • 22
6
votes
4 answers

Reproduce a 'The Economist' chart with dual axis

I was trying to replicate this chart from The Economist (the one on the left). The chart plots the number of billionaires in Russia on the left y-axis and the number of billionaires in rest of the world on the right. Create the chart for Russian…
drawar
  • 243
  • 2
  • 10
1
2
3
9 10