Skip to content

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

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?

Hello There!

If you like what you read, please support our publication by sharing it with your friends, family and colleagues. We're an ad-supported publication. So, if you're running an Adblocker, we humbly request you to whitelist us.

Share on facebook
Share on whatsapp
Share on twitter
Share on reddit
Share on linkedin
Share on pocket
Share on pinterest
Share on telegram
Share on stumbleupon
Share on digg
Share on tumblr
Share on email
Share on skype
Share on xing
Share on vk
Share on odnoklassniki
Share on mix






No more posts to show


>