Skip to content

Instantly share code, notes, and snippets.

@baptiste
Created June 3, 2012 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baptiste/2865293 to your computer and use it in GitHub Desktop.
Save baptiste/2865293 to your computer and use it in GitHub Desktop.
fixed width gtable
library(ggplot2)
library(grid)
fixed_width <- function(p, width = unit(3, "cm"),
draw = FALSE){
gt <- ggplot_gtable(ggplot_build(p))
panel_index <- gt$layout$r[gt$layout$name == "panel"]
gt$widths[[panel_index]] <- width
if(draw) grid.draw(gt)
class(gt) <- c(class(gt), "grob")
invisible(gt)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment