Solving that old “Error in plot.new() : figure margins too large”

infoart.ca
2 min readJul 27, 2021

--

Combining multiple graphs in R is a breeze, until of course that old error:

> par(mfrow=c(2,2))
> for (i in 1:4){
+ hist(iris[,i])
+ }
Error in plot.new() : figure margins too large

Unfortunately, the error message doesn't give a clear message about the root of the problem like in most R errors. Luckily, it can be resolved in a single command by resetting the default margine size of c(5.1, 4.1, 4.1, 2.1).

par(mar=c(5.1,4.1,4.1,2.1))

The scaling that works best for me is

par(mar=c(3.5, 3.5, 2, 1))

Finally we get the desired graph with success:

But not quite, there is still room for improvement as the axis labels are currently overlapping with the titles of the downstairs charts. This can be corrected by resetting the mgp that defines the the axis label locations relative to the edge of the inner plot window. The values are defaulted to:

> par(“mgp”)
[1] 3 1 0

And the one makes it look neat is:

par(mgp=c(2.4, 0.8, 0))

The final product looks like:

Also, we had the option of resetting both of the parameters in the same command:

par(mar=c(3.5, 3.5, 2, 1), mgp=c(2.4, 0.8, 0))

--

--

infoart.ca

Center for Social Capital & Environmental Research | Posts by Bishwajit Ghose, lecturer at the University of Ottawa