Proposal for improved grid() [non-backward compatible]

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Mon, 6 Sep 1999 10:47:10 +0200

```Not many of you will use grid() widely, probably.
Also, two months ago, Paul Murrell said on R-help (topic "grid command")

PM>> i think the abline() solution is the best for doing what grid() won't.
PM>> like you say, grid() is just a simple front-end to abline().

grid() *is* too simple to be of practical use.

I propose the following which is of some practical use,
since it uses much more useful defaults:

grid <- function (nx=NULL, ny=NULL, col="lightgray", lty="dotted")
{
if (is.null(nx)|| nx >= 1) {
axp <- par("xaxp")
if(is.null(nx)) nx <- axp[3]
abline(v = seq(axp[1],axp[2],len=1+nx), col = col, lty = lty)
}
if (is.null(ny)|| ny >= 1) {
axp <- par("yaxp")
if(is.null(ny)) ny <- axp[3]
abline(h = seq(axp[1],axp[2],len=1+ny), col = col, lty = lty)
}
}

Try e.g.

plot(1:10, panel.first = grid(col="red"))
qqnorm(rnorm(100), panel.first=grid())
plot(1:10, panel.first=grid(ny=4))
plot(1:10, panel.first=grid(ny=0))

-----------

The only "problem":  It's not backwards compatible.
Does anyone have a problem with that?

Martin Maechler <maechler@stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO D10	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```