To solve the R "Error in plot.new() : figure margins too large," expand the plot panel in RStudio and run your code again, or run the code par("mar")
and par(mar=c(1, 1, 1, 1))
.
The error occurs when the plot panel in RStudio is too small for the margins of the plot you want to create.
Here is an example of how the error occurs.
# Attempt to create scatterplot
# ⛔️ Error in plot.new() : figure margins too large
plot(1:30)
Expand the plot panel in RStudio and run your code again.
If this doesn't work, reduce the margins by running the following code. Then run your plot again.
# 👇️ Check current margins
par("mar")
# You should get the following for the bottom, left, top, and right margins
# These are the default margins
>> 5.1 4.1 4.1 2.1
# Reduce margins to 1
par(mar=c(1, 1, 1, 1))
# If this doesn't work, try reducing margins to 2
par(mar=c(2, 2, 2, 2))
# Rerun your plot
plot(1:30)
The par()
function sets the margins of a plot to these defaults:
We can reduce these margins to 1 by running par(mar=c(1, 1, 1, 1))
To solve the R "Error in plot.new() : figure margins too large," expand the plot panel in RStudio and run your code again, or run the code par("mar")
and par(mar=c(1, 1, 1, 1))
.
Related tutorials curated for you
Error in plot.new() : figure margins too large
R: the condition has length > 1 and only the first element will be used
$ operator is invalid for atomic vectors in R
Error in file(file, "rt") : cannot open the connection
Non-numeric argument to binary operator error in R