[Rd] [patch] add=TRUE in plot.default()

Andrew Clausen clausen at econ.upenn.edu
Sun Mar 9 04:11:19 CET 2008


Hi all,

As long as I've used R, add=TRUE hasn't worked in contexts like this:

	f <- function(x) x^2
	X <- seq(0, 1, by=1/4)
	plot(f, col="blue")
	plot(X, f(X), col="red", type="l", add=TRUE)

I attached a fix for version 2.6.2.

Cheers,
Andrew

-------------- next part --------------
diff --git a/src/library/graphics/R/plot.R b/src/library/graphics/R/plot.R
index 233b11e..ad3529e 100644
--- a/src/library/graphics/R/plot.R
+++ b/src/library/graphics/R/plot.R
@@ -46,16 +46,24 @@ plot.default <-
     function(x, y = NULL, type = "p", xlim = NULL, ylim = NULL,
              log = "", main = NULL, sub = NULL, xlab = NULL, ylab = NULL,
              ann = par("ann"), axes = TRUE, frame.plot = axes,
-             panel.first = NULL, panel.last = NULL, asp = NA, ...)
+             panel.first = NULL, panel.last = NULL, asp = NA, add=FALSE, ...)
 {
+    xlabel <- if (!missing(x)) deparse(substitute(x))
+    ylabel <- if (!missing(y)) deparse(substitute(y))
+    if (add) {
+	log <- paste(ifelse(unlist(par("xlog", "ylog")), c("x", "y"), ""),
+		     collapse="")
+	xy <- xy.coords(x, y, xlabel, ylabel, log=log)
+	plot.xy(xy, type, ...)
+	return(invisible())
+    }
+
     ## These col, bg, pch, cex can be vectors, so exclude them
     ## Also, axis and box accept some of these
     localAxis <- function(..., col, bg, pch, cex, lty, lwd) Axis(...)
     localBox <- function(..., col, bg, pch, cex, lty, lwd) box(...)
     localWindow <- function(..., col, bg, pch, cex, lty, lwd) plot.window(...)
     localTitle <- function(..., col, bg, pch, cex, lty, lwd) title(...)
-    xlabel <- if (!missing(x)) deparse(substitute(x))
-    ylabel <- if (!missing(y)) deparse(substitute(y))
     xy <- xy.coords(x, y, xlabel, ylabel, log)
     xlab <- if (is.null(xlab)) xy$xlab else xlab
     ylab <- if (is.null(ylab)) xy$ylab else ylab


More information about the R-devel mailing list