[R] xyplot: Can I identify groups but not use them for regression?

Sundar Dorai-Raj sdorairaj at gmail.com
Sat Sep 19 00:48:50 CEST 2009


I think this ought to work for you:

library(lattice)
set.seed(42)
d <- data.frame(year  = c(rep(2007,12), rep(2008,12)),
                treatment = rep(LETTERS[1:3], each = 4, times = 2))
d$cover <- rnorm(nrow(d))
d$variable <- rnorm(nrow(d))

xyplot(variable ~ cover | year, d,
       panel = function(x, y, ...) {
         panel.superpose(x, y, ...)
         panel.lmline(x, y, ...)
       },
       groups = treatment)

HTH,

--sundar

On Fri, Sep 18, 2009 at 3:42 PM, Seth W Bigelow <sbigelow at fs.fed.us> wrote:
> I wish to identify groups representing different treatments, but to plot
> them and do a regression using a continuous variable ("cover")
> ignoring the groupings.
>
> d$year <- NA
> d$year <-c(rep(2007,12), rep(2008,12))
> d$treatment <- c(rep("A",4),rep("B",4),rep("C",4), rep("A",4), rep("B",4),
> rep("C",4))
> d$cover <- rnorm(24)
> d$variable <- rnorm(24)
>
> xyplot(variable ~ cover | year, d,
>        type=c("p","r"),
>        groups=treatment
>        )
>
> As it stands, a different regression line is plotted for each treatment.
> Oh, and how do I display the actual numeric value of year (e.g., "2007")
> in the strip, rather than the word "year"?
>
> --Seth
>
>
>
> Dr. Seth  W. Bigelow
> Biologist, USDA-FS Pacific Southwest Research Station
> 1731 Research Park Drive, Davis California
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>




More information about the R-help mailing list