What causes the error “plot.new() : figure margins too large” and how can it be fixed? 2

What causes the error “plot.new() : figure margins too large” and how can it be fixed?

“The error “plot.new() : figure margins too large” occurs when the margins specified for a plot are too large, causing the plot to exceed the available space. This can happen when the margins are set too wide, or when the plot is trying to fit into a smaller display area. To fix this error, the margins should be adjusted to a smaller size or the plot should be resized to fit into the available space.”

Fix: error in plot.new() : figure margins too large


One error you may encounter in R is:

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

This error occurs when the plot panel in RStudio is too small for the margins of the plot that you’re attempting to create.

This tutorial shares exactly how to fix this error.

How to Reproduce the Error

Suppose we attempt to create the following plot in R:

#attempt to create scatterplot
plot(1:30)

We receive the following error:

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

We receive this error because the plot panel is extremely small (notice how small the panel is in the bottom left corner) and so the margins of the plot can’t be displayed in such a small panel.

Method #1: Fix the Error by Increasing the Size of the Plot Panel

The easiest way to fix this error is to increase the size of the plotting panel in RStudio:

plot(1:30)

Notice that we don’t receive an error because the plotting panel was large enough to display the margins of the plot.

Method #2: Fix the Error by Using the par() Function

  • Bottom margin: 5.1
  • Left margin: 4.1
  • Top margin: 4.1
  • Right margin: 2.1

However, we can use the following syntax to make the margins smaller:

#adjust plot margins
par(mar = c(1, 1, 1, 1))

#create scatterplot
plot(1:30)

The plot is successfully displayed in the plotting panel in RStudio because we reduced the margins so much.

Method #3: Fix the Error by Shutting Down Current Plotting Device

If neither of the previous methods are able to fix the error, then you may need to use the following code to shut down the current plotting device:

dev.off()

In some cases, this may fix the error because it removes any plot settings that were used for previous plots and may be interfering with your current plot.

The following tutorials explain how to perform other common plotting functions in R:

Cite this article

stats writer (2024). What causes the error “plot.new() : figure margins too large” and how can it be fixed?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/what-causes-the-error-plot-new-figure-margins-too-large-and-how-can-it-be-fixed/

stats writer. "What causes the error “plot.new() : figure margins too large” and how can it be fixed?." PSYCHOLOGICAL SCALES, 5 May. 2024, https://scales.arabpsychology.com/stats/what-causes-the-error-plot-new-figure-margins-too-large-and-how-can-it-be-fixed/.

stats writer. "What causes the error “plot.new() : figure margins too large” and how can it be fixed?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/what-causes-the-error-plot-new-figure-margins-too-large-and-how-can-it-be-fixed/.

stats writer (2024) 'What causes the error “plot.new() : figure margins too large” and how can it be fixed?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/what-causes-the-error-plot-new-figure-margins-too-large-and-how-can-it-be-fixed/.

[1] stats writer, "What causes the error “plot.new() : figure margins too large” and how can it be fixed?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, May, 2024.

stats writer. What causes the error “plot.new() : figure margins too large” and how can it be fixed?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top