This is a follow-up to my earlier posting this month.  For your
consideration, here are patches for loess.R and scatter.smooth.Rd that
will allow either of the following to work:
  scatter.smooth(x,y,...)
  scatter.smooth(y~x,...)

Here are some test cases:

attach(cars)
scatter.smooth(speed,dist,main="dist,speed")
scatter.smooth(speed,dist,main="dist,speed",xlab="",ylab="")
scatter.smooth(cars,main="cars")
scatter.smooth(cars,main="cars",xlab="Speed",ylab="Distance")
scatter.smooth(dist~speed,main="dist~speed")
scatter.smooth(dist~speed,main="dist~speed",xlab="")
scatter.smooth(dist~speed,main="dist~speed",ylab="")


Kevin Wright



----- Patch to loess.R -----

/cygdrive/c/R-devel/src/library/stats/R>diff -u loess.R loess.new.R
--- loess.R     2005-03-01 19:48:13.000000000 -0600
+++ loess.new.R 2005-05-20 09:12:58.792718700 -0500
@@ -403,19 +403,28 @@
 }

 scatter.smooth <-
-    function(x, y, span = 2/3, degree = 1,
+    function(x, y=NULL, span = 2/3, degree = 1,
             family = c("symmetric", "gaussian"),
-            xlab = deparse(substitute(x)), ylab = deparse(substitute(y)),
+            xlab = NULL, ylab = NULL,
             ylim = range(y, prediction$y, na.rm = TRUE),
              evaluation = 50, ...)
 {
-    if(inherits(x, "formula")) {
-       if(length(x) < 3) stop("need response in formula")
-       thiscall <- match.call()
-       thiscall$x <- x[[3]]
-       thiscall$y <- x[[2]]
-       return(invisible(eval(thiscall, sys.parent())))
-    }
+  xlabel <- if (!missing(x)) deparse(substitute(x))
+  ylabel <- if (!missing(y)) deparse(substitute(y))
+  xy <- xy.coords(x, y, xlabel, ylabel)
+
+  x <- xy$x
+  y <- xy$y
+  xlab <- if(is.null(xlab)) xy$xlab else xlab
+  ylab <- if(is.null(ylab)) xy$ylab else ylab
+
+#    if(inherits(x, "formula")) {
+#      if(length(x) < 3) stop("need response in formula")
+#      thiscall <- match.call()
+#      thiscall$x <- x[[3]]
+#      thiscall$y <- x[[2]]
+#      return(invisible(eval(thiscall, sys.parent())))
+#    }
     prediction <- loess.smooth(x, y, span, degree, family, evaluation)
     plot(x, y, ylim = ylim, xlab = xlab, ylab = ylab, ...)
     lines(prediction)

----- patch to scatter.smooth.Rd -----

/cygdrive/c/Temp/R-devel/src/library/stats/man>diff -u scatter.smooth.Rd
scatter.smooth.new.Rd
--- scatter.smooth.Rd   2004-10-29 09:46:19.000000000 -0500
+++ scatter.smooth.new.Rd       2005-05-20 09:54:40.444634400 -0500
@@ -8,7 +8,7 @@
 \usage{
 scatter.smooth(x, y, span = 2/3, degree = 1,
     family = c("symmetric", "gaussian"),
-    xlab = deparse(substitute(x)), ylab = deparse(substitute(y)),
+    xlab = NULL, ylab = NULL,
     ylim = range(y, prediction$y, na.rm = TRUE),
     evaluation = 50, \dots)

@@ -33,6 +33,9 @@
   \code{loess.smooth} is an auxiliary function which evaluates the
   \code{loess} smooth at \code{evaluation} equally spaced points
   covering the range of \code{x}.
+
+  The x,y arguments of \code{scatter.smooth} can be specified any of the
+  ways accepted by \code{\link{xy.coords}}.
 }
 \value{
   For \code{scatter.smooth}, none.

----- end -----

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to