0

Please I wonder to send a pdf file containing the multi barplot I generated using ggplot2 / geom_bar() and facet_wrap(). It is required that the dimension of each single barplot must measure 2 cm * 2 cm (W*H). Unfortunately I didn't fid a way to do that, example if I run the example of the command line (above), it to big in an A4 paper.

I'm asking if there is a function / package / solution that allow to define the exact size of every single barplot in my future file, Any help will be much appreciated.

pdf("result.pdf" , width = 8.27 , height = 11.69) 

ggplot(mtcars, aes(x=gear,  y=mpg, fill=vs)) +  
  geom_bar(position="dodge", stat="identity") +
  facet_wrap(~ carb, ncol=2)

dev.off()
TobiO
  • 1,335
  • 1
  • 9
  • 24
Cherif
  • 33
  • 1
  • 6

1 Answers1

0

You need the theme() functionality.

pdf("result1.pdf" , width = 8.27 , height = 11.69) 

ggplot(mtcars, aes(x=gear, y=mpg, fill=vs)) +
  geom_bar(position="dodge", stat="identity") + facet_wrap(~ carb, ncol=2) +
  theme(panel.margin = unit(c(2, 2, 2, 2), "cm"))

dev.off()
Divi
  • 1,614
  • 13
  • 23
  • plot.margin allow to resize the margin around the entire plot – Cherif May 13 '16 at 09:24
  • @Cherif You will need `panel.margin` from what I understand. I am not entirely sure if you want the `unit` to be `2cm` though for each panel. Do go through the ggplot page for more options that may suit your problem http://docs.ggplot2.org/0.9.2.1/theme.html – Divi May 13 '16 at 14:22