James
James

Reputation: 1098

R: increase figure region to accommodate margins without altering plot size

I would like to increase the size of my margins without altering the size of my plot region. What I'm doing is:

  1. plotting my data, then querying the values of mai (margin size in inches) and fin (figure region dimension in inches).
  2. adjusting mai by one inch at bottom and left.
  3. adjusting fin by one inch for width and one inch for height.
  4. re-plotting data.

However, I always get the error:

Error in plot.new() : figure region too large

Can anyone help? There's obviously something I don't understand about how mai and fin interact.

Here is an example:

x=c(1,2)
y=c(2,4)

plot(x,y)
init_fin <- par("fin") #gives 7 7
init_mai <- par("mai") #gives 1.02 0.82 0.82 0.42

final_fin <- init_fin + 1 #now 8 8
par(mai=c(2.02,1.82,0.82,0.42), fin=final_fin)
plot(x,y)

ERROR:

Error in plot.new() : figure region too large

Upvotes: 0

Views: 11176

Answers (2)

Md Ahsanul Himel
Md Ahsanul Himel

Reputation: 345

Use par(mai = c(bottom, left, top, right)) before the plot. It will create extra space around the plot area. Change values of bottom, left, top and right according to your taste.

Upvotes: 1

baptiste
baptiste

Reputation: 77116

this error depends on the device you're using, I see it all the time with Rstudio because the plot panel is quite small on my laptop screen, and R thinks there's not enough space to display the graphic. One option is to open a bigger device window explicitly, e.g.

dev.new(width=10, height=10)

just before your last plot.

Upvotes: 4

Related Questions