Skip to content

How to fix error in plot new: Figure margins too large?

  • by
  • 2 min read

If you haven’t ever run into random errors when building or compiling your program or script, you haven’t stepped into the world of programming. Dealing with errors is the bread and butter of every programmer in every language out there, and R isn’t any different. 

In this article, we’re taking a look at the “Error in plot new: Figure margins too large?” error in R, investigating its causes and figuring out how to fix this problem. 


What causes this error?

The following two causes mainly trigger the error.

  • The plot window is too short: If your default plot margins are’t correct the error will be triggered.
  • Plot are amrgins aren’t correctly defined in your code: If you’re using the plot() or any other graphing function to make a boxplot, histogram or any other high resolution figure plot function and you’ve not defined the margins for the graphing fuction correctly, you’ll trigger the error. 

Also read: Python vs R: Which one is better?


How to fix this error?

There are two solutions for both the reasons you might be facing in this situation.

When the plot window is too short

All you have to do here is head into R-Studio and move your cursor over to the top of the graph window until you see the four-way layout panel arrows. Just drag the top of the plot window upwards until the variable list.

Top 7 games for kids to learn coding | Candid.Technology

If this was the source of your problem, you should be able to run your code unchanged, and it should function just fine. 


When the plot margins aren’t defined correctly

All you have to do is add a simple line of code above your plot() function to fix this problem. 

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

The aforementioned function fixes the problem by resetting the plot are margins to an acceptable value hence erasing the error in the process. 

Also read: How to flatten a list and list of lists in Python?

Yadullah Abidi

Yadullah Abidi

Yadullah is a Computer Science graduate who writes/edits/shoots/codes all things cybersecurity, gaming, and tech hardware. When he's not, he streams himself racing virtual cars. He's been writing and reporting on tech and cybersecurity with websites like Candid.Technology and MakeUseOf since 2018. You can contact him here: yadullahabidi@pm.me.

>