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!
To visualize how R creates plot margins, look at margin Figure 11.20. You can adjust the size of the margins by specifying a margin parameter using the syntax par(mar = c(bottom, left, top, right)) , where the arguments bottom , left … are the size of the margins. The default value for mar is c(5.1, 4.1, 4.1, 2.1).
Use par(mai = c(bottom, left, top, right)) before the plot. It will create extra space around the plot area.
par(mai=c(1.02,0.82,0.82,0.42)) The numbers used above are the default margin settings in R. You can verify this by firing up the R prompt and typing par(“mar”) or par(“mai”). You should get back a vector with the above values.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With