Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in frame() : figure margins too large

Tags:

plot

r

I am trying to create a matrix of plots, but I want the upper left corner to be blank. So I'm using:

frame()

To which R responds:

Error in frame(): figure margins too large

I'm using the following two lines to create my layout:

plotIDs <- matrix(c(1:16), 4, 4, byrow = T);
layout(plotIDs, widths = c(0.5,1,1,1,1), heights = c(0.5,1,1,1,1));

and this gives me the following layout:

4 by 4 layout with first row and col at half height

If I then issue frame() I get the above error. What am I doing wrong? I don't see any way to specify a height or a width for the frame() command (just an alias for plot.new())?

like image 942
M. Tibbits Avatar asked Jun 28 '11 01:06

M. Tibbits


People also ask

What does error in plot new figure margins too large mean?

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.

What does it mean when my margins are too large?

The message means that the margins in the figure are too large and do not leave enough space for the plot. You can start with frame () or plot.new (), or just plot into the first panel. Note you will need to consider what is an appropriate margin setting for each of your different panels, and fine-tune label sizes and so on.

What is error in plot new()?

The error in plot.new () : figure margins too large occur if the plot panel in the RStudio is too small for the margins you are trying to create. In this tutorial, we will learn how to resolve error in plot.new () : figure margins too large issue using several ways What is error in plot.new () : figure margins too large?

Why can't I plot a plot with the default margins?

The problem is that the small figure region 2 created by your layout () call is not sufficiently large enough to contain just the default margins, let alone a plot. More generally, you get this error if the size of the plotting region on the device is not large enough to actually do any plotting.


2 Answers

The message means that the margins in the figure are too large and do not leave enough space for the plot.

Try reducing the margin:

op <- par(mar = par("mar")/2)
plot.new()  ## this is optional for this example
plot(1:10)
par(op)  ## tidy up to restore the default par setting

You can start with frame() or plot.new(), or just plot into the first panel. Note you will need to consider what is an appropriate margin setting for each of your different panels, and fine-tune label sizes and so on.

For a totally blank panel, you might as well kill the margin completely:

op <- par(mar = rep(0, 4))
plot.new()
par(op)
like image 94
mdsumner Avatar answered Oct 06 '22 00:10

mdsumner


You can leave panels blank using layout by having a 0 in the matrix, so if you use 0:15 instead of 1:16 then the 1st panel will be blank without you needing to skip. Of course you will neet to set margins and cex for the rest of the panels.

like image 30
Greg Snow Avatar answered Oct 05 '22 22:10

Greg Snow