Skip to content

custom panel help in lattice

2 messages · Jon Loehrke, Deepayan Sarkar

1 day later
#
On Sun, Dec 7, 2008 at 9:37 AM, Jon Loehrke <jloehrke at umassd.edu> wrote:
You end up calling smooth.spline() with arguments it doesn't
recognize. One work-around is defining 'panel.smooth.spline' as
follows:

panel.smooth.spline <-
    function(x, y,
             w=NULL, df, spar = NULL, cv = FALSE,
             lwd=plot.line$lwd, lty=plot.line$lty,col, col.line=plot.line$col,
             type, horizontal=FALSE,... )
{
           x <- as.numeric(x)
           y <- as.numeric(y)
           ok <- is.finite(x) & is.finite(y)
           if (sum(ok) < 1)
               return()
           if (!missing(col)) {
               if (missing(col.line))
                   col.line <- col
           }
           plot.line <- trellis.par.get("plot.line")
           if (horizontal) {
               spline <-
                   smooth.spline(y[ok], x[ok],
                                 w=w, df=df, spar = spar, cv = cv)
               panel.lines(x = spline$y, y = spline$x, col = col.line,
                   lty = lty, lwd = lwd, ...)
           }
           else {
               spline <-
                   smooth.spline(x[ok], y[ok],
                                 w=w, df=df, spar = spar, cv = cv)
               panel.lines(x = spline$x, y = spline$y, col = col.line,
                   lty = lty, lwd = lwd, ...)
           }
       }

-Deepayan