r-lib / gtable

The layout packages that powers ggplot2
https://gtable.r-lib.org
Other
87 stars 18 forks source link

Extract only plot object from gtable #48

Closed GiBacci closed 5 years ago

GiBacci commented 9 years ago

Is there a way to extract the plot region of a gtable object without axes, legend, text... ? I need to print a plot which occupies the hole plotting area (without any black margin) in order to align several ggplot objects using grid.arrange. Here is some example code:

p1 <- ggplot2(...) + geom_something(...)
p2 <- ggplot2(...) + geom_something(...)

pp1 <- extract_plot_function_needed(ggplotGrob(p1))
pp2 <- extract_plot_function_needed(ggplotGrob(p2))

grid.newpage()
grid.arrange(pp1, pp1, heigths=c(1,3))

I hope I was clear enough!

Thanks in advance,

Giovanni

thomasp85 commented 5 years ago

the find_panel() function in ggplot2 can be used to find the region where the plot area resides and can then be used for subsetting the gtable