Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R pdf set margin

Tags:

plot

margin

r

pdf

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

like image 584
RockScience Avatar asked Nov 15 '16 06:11

RockScience


People also ask

How do you set margins in R?

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).

How do I increase plotting region in R?

Use par(mai = c(bottom, left, top, right)) before the plot. It will create extra space around the plot area.

How do you identify the default margins of graph using par function give the default margins?

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.


Video Answer


1 Answers

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.

like image 60
Vaishnavi Phadnis Avatar answered Oct 22 '22 15:10

Vaishnavi Phadnis