How To Fix Rstudio: Error in plot.new() : figure margins too large

The “error in plot new figure margins too large” error is an interesting one because not all of its occurrences result from your program or data. This error message occurs when there is a problem with the margin figure size, width, and height default settings while graphing data within base R programming or the Rstudio UI.

This error occurs when your parameter settings for the margin figure within the Rstudio UI are not compatible with the plot function you are using, which often happens with a high resolution figure region in a graphing function in base R. Now let’s go through some different questions that may arise from this error in plot new figure margins too large problem.

When Does This Error Occur?

This error message has two different ways it can occur. One of them is a result of a margin change in the code in your data frame file or vector and the other from arrangement of your windows in R-Studio . You’ll often see this when you’re generating a scatter plot. Fixing it usually requires tweaking your graphical parameters in your r code (and not adjusting the underlying data).

Issue #1 – The Plot Window is Too Short.

Here is an example of this plot.new error in r under the situation where the plot window is too short. There is no reason from in the output code why you should be getting this error message when plotting your data. Your default value plot margins should be correct, however your r plot size just is not working in this case.

# R error example #1: figure margins too large
# error in plot new figure margins too large
 > x = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
 > y= x^2
 > plot(x, y)
 Error in plot.new() : figure margins too large

If you run the three lines of this code text without the top of the graphing window at the bottom of the screen, it will produce a standard graph of the squares of the first ten whole numbers on the plot. However, here we are seeing the same error, “error in plot.new() : figure margins too large.”

Issue #2 – Plot Area Margins Messed Up in The Code.

Here, the first line in the code messes up the margins for the graphing function, resulting in this error message when you use plot() and other graphing functions to make a boxplot, histogram, or other high resolution figure plot function.

# R error example #2: figure margins too large 
> par(mar=c(0, 0, 10, 100))
 > x = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
 > y= x^2
 > plot(x, y)
 Error in plot.new() : figure margins too large

To mess up the column margins, this code text does not have to be right before the graphics device command that is producing the error value. It can even be from an earlier run of the code. Your R margins can be a tricky thing to work with, so knowing how to change plot dimensions, axes, and your pointsize plotting region in R is an invaluable skill for any programmer.

How to Fix This Error.

How do you fix too big margins in R? Fortunately, the answer solution to this error question is quite easy. It only requires some simple adjustments, either to your R-Studio plot window or your code.

If The Plot Window Is Too Short…

If this is your problem then just go into R-Studio and move the cursor to the top of the graph window until you get four-way layout panel arrows. Then simply drag the top the plot region upward to the variable list. If this was the source of your figure region problem, running the code unchanged will produce the expected graph. Your outer default margins should be the correct size, the plot panel will fit, and your R plot axis label should not be cut off.

If The Plot Margins Are Messed Up In The Code…

If the problem was with the plotting area in your code then simply add “par(mar=c(1, 1, 1, 1))” to your code as illustrated below.

# R Error avoided: figure margins too large 
> x = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
 > y= x^2
 > par(mar=c(1, 1, 1, 1))
 > plot(x, y)

This should fix the problem producing this error regardless of where the margin change occurs in your program. What is par mar in R? This par function solution fixes the problem by resetting the plotting area margins to acceptable values, eliminating the error. Your default margins should be fixed, and your R plots should now be nice and readable.

Addresses R Error: error in plot.new() : figure margins too large

Having Trouble? Check Out These Fixes For Other R Errors:

Scroll to top
Privacy Policy