9

I am trying to set the figure margin for a pdf generated with R. Using mar, I can reduce the plot margins. However the resulted plot is still a square in the middle of the page instead of using all the space. How can I change that?

pdf(file = "test.pdf", paper="a4r")
par(mar=c(0,0,0,0)+0.1)
plot(1:10,1:10)
dev.off()

Thank you!

enter image description here

RockScience
  • 17,932
  • 26
  • 89
  • 125
  • Use the `width` and `height` arguments to `pdf`, e.g., `pdf(file = "test.pdf", width=8, height=5)`. – eipi10 Nov 15 '16 at 06:13
  • 1
    You might still want to set the margins as well. If you want the top and right margins to be minimal and the x and y axis titles to be right at the edge of the plot, something like `par(mar=c(4,4,0.5,0.5))` would do that. – eipi10 Nov 15 '16 at 06:20
  • thanks, that works. Weird that there is no other alternative than to avoid using paper="a4r"... – RockScience Nov 15 '16 at 07:15
  • You can still use `paper="a4r"`, but then your plot will have a margin unless you use `width=11.69, height=8.27` (or larger measurements with the same aspect ratio). – eipi10 Nov 15 '16 at 14:53

1 Answers1

2

Within pdf(), change the width and height arguments (https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/pdf.html). The default values are 7 and 7, which is likely why there is extra space on your page.