How do I remove margins surrounding the plot area completely?

445 views
Skip to first unread message

Chunqiao Luo

unread,
Dec 12, 2016, 9:21:24 AM12/12/16
to ggplot2

I am using ggplot2 in creating an R package. How can I select plot panel only? The code below does not work any more. 

 

# Get the ggplot grob

gt = ggplotGrob(p)

 

# Select plot panel only

gt = gt[3,4]


And if I use theme() such as theme(plot.margin=unit(c(0,0,0,0), "null"))+ theme(panel.margin=unit(c(0,0,0,0), "null")), there are still some margins when I save the plot. Is there a way to eliminate plot margins and panel margins completely? Could you give me a hint? 


Please see the link below for more details.

 

http://stackoverflow.com/questions/31254533/when-using-ggplot-in-r-how-do-i-remove-margins-surrounding-the-plot-area

 

Thank you very much in advance! 

Crump, Ron

unread,
Dec 12, 2016, 9:41:07 AM12/12/16
to Chunqiao Luo, ggplot2
Hi,
I think the answer is there, courtesy of the comment by baptiste below the
accepted answer.

Instead of:
gt <- gt[3,4]

try:
library(gtable)
gt <- gtable_filter(gt, "panel")

and then continue as in the reproducible example included in the accepted
answer on stackoverflow.

Ron.

Reply all
Reply to author
Forward
0 new messages