Re: [R] Conditionally Updating Lattice Plots

From: Deepayan Sarkar <deepayan.sarkar_at_gmail.com>
Date: Mon, 21 Jul 2008 17:31:40 -0700

On 7/20/08, Bryan Hanson <hanson_at_depauw.edu> wrote:
> Hi All...
>
> I can¹t seem to find an answer to this in the help pages, archives, or
> Deepayan¹s Lattice Book.
>
> I want to do a Lattice plot, and then update it, possibly more than once,
> depending upon some logical options. Code below; it produces a second plot
> page when the second update is called, from which I would infer that you
> can't update the update or I'm not calling it correctly. I have a nagging
> sense too that the "real" way to do this is with a non-standard use of
> panel.superpose but I don't quite see how to do that from available
> examples.

I think you are misunderstanding the concept of updating and the purpose of the 'more' argument. What you want is most easily done as follows:

fancy.lm <- function(x, y, fit = TRUE, resid = TRUE){

    model <- lm(y ~ x)
    y.pred <- predict(model)
    res.x <- as.vector(rbind(x, x, rep(NA,length(x))))     res.y <- as.vector(rbind(y, y.pred, rep(NA,length(x))))

    xyplot(y ~ x, pch = 20,

           panel = function(...) {
               panel.xyplot(...) # not strictly necessary if I
understand correctly
               if (fit) {
                   panel.abline(model, col = "red")
               }
               if (resid) {
                   panel.xyplot(res.x, res.y, col = "lightblue", type = "l")
               }
           })

}

x <- jitter(c(1:10), factor = 5)
y <- jitter(c(1:10), factor = 10)
fancy.lm(x, y, fit = TRUE, resid = TRUE)

-Deepayan



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 22 Jul 2008 - 00:34:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 Jul 2008 - 03:32:02 GMT.

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

list of date sections of archive