Skip to content
Prev 44211 / 398503 Next

How to plot a blank plot

On Fri, 2004-02-13 at 15:31, Don MacQueen wrote:
A slightly shorter version of the same thing is:

plot(1, ann = FALSE, axes = FALSE, type = "n")

This gives you a blank plot area with the following, perhaps most
important, par value:
[1] 0.568 1.432 0.568 1.432


plot.new() and frame() give you the following:
[1] -0.04  1.04 -0.04  1.04

Recall that par("usr") is c(x1, x2, y1, y2).


In either case, the above values can be overridden by a subsequent call
to par("usr"), such as the following:

par(usr = c(0, 1, 0, 1))

Thus setting the x and y ranges to known values if one needs them a
particular way.  

Another way of accomplishing the same thing with a single function call
is:

plot(1, ann = FALSE, axes = FALSE, xlim = c(0, 1), ylim = c(0, 1), 
     type = "n", xaxs = "i", yaxs = "i")

The use of 'xaxs' and 'yaxs' sets the ranges of the x and y axes to
exactly the limits specified, rather than extending both by 4%, which is
the default (with values of "r"). This yields:
[1] 0 1 0 1

instead of:
[1] -0.04  1.04 -0.04  1.04

as seen above from a default call to plot.new() or frame().

So, ultimately, if you are not going to actually draw anything in the
particular plot region as is Adrian's situation, such that you are not
concerned with the coordinates and other details, plot.new() and frame()
are the quickest as Don, I and others have pointed out. 

Indeed, as ?frame points out:

"...('frame' is an alias for 'plot.new')..."
function () 
.Internal(plot.new())
<environment: namespace:base>


So which one you pick is really a personal preference choice. As is the
case frequently with R, there is more than one way to get to the same
end point, some more 'elegant' than others.

HTH,

Marc Schwartz