# [Rd] setting up a plot without plotting any data

From: Bill Dunlap <bill_at_insightful.com>
Date: Fri 17 Nov 2006 - 19:45:15 GMT

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(...))

E.g.,

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
360-428-8146

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

R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Nov 18 06:47:52 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 17 Nov 2006 - 21:30:46 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.