[Rd] setting up a plot without plotting any data

Bill Dunlap bill at insightful.com
Fri Nov 17 20:45:15 CET 2006

Someones you need to set up a plot before the
data is ready to plot.  You know the desired
axis limits (xlim and ylim), but don't have
the data all in one vector.  You would like to
set up the coordinate system, perhaps draw the
axes and titles, but draw no points.  You can do that with
   plot(x=xlim, y=ylim, type="n", xlab="", ylab="")
In R you could use ann=FALSE instead of xlab="",
ylab="".  In either you could supply non-null values
for xlab and ylab but the default, xlab="xlim",
ylab="ylim", would not be desirable.  You could
supply other scaling-related arguments like log="x".

We could write an method for plot with signature
x="missing",y="missing" so the syntax for the above
would be a bit more natural
   plot(xlim=xlim, ylim=ylim)
If you want non-null xlab or ylab, supply them.
If you don't want axes, supply axes=FALSE, just
as with the usual plot().  Would this be desirable?
(It made things easier to explain to my son.)

The following code does that in either R or Splus:

   .plot.noxy <-
   function(..., xlim, ylim, xlab = "", ylab = "")
           stopifnot(length(xlim) == 2, all(is.finite(xlim)))
           stopifnot(length(ylim) == 2, all(is.finite(ylim)))
           plot(type = "n", x = xlim, y = ylim, ..., xlim = xlim, ylim = ylim,
                   xlab = xlab, ylab = ylab)
   setMethod("plot", sig=signature(x="missing", y="missing"),
           definition=function(x, y, ...).plot.noxy(...))

   plot(xlim=c(-2,2), ylim=c(-2,2)) # set up plot and draw axes
   for(i in -10:10)points( (.8+.7i)^i) # add points to graph

Bill Dunlap
Insightful Corporation
bill at insightful dot com

 "All statements in this message represent the opinions of the author and do
 not necessarily reflect Insightful Corporation policy or position."

More information about the R-devel mailing list