[R] RE: Trellis graph and two colors display

Rogers, James A [PGRD Groton] James_A_Rogers at groton.pfizer.com
Wed Jan 14 14:00:14 CET 2004


>From: "Patrick Giraudoux" <patrick.giraudoux at univ-fcomte.fr>
>
>Hello,
>
>I would like to display two groups of dots in different colors 
>or style and additionnaly a linear regression for all the dots in
>panel plots of a Trellis graph.  Actually to get in each panel 
>the equivalent of:
>
>plot(x[mois==3],y[mois==3],col="blue")
>points(x[mois==9],y[mois==9],col="red")
>abline(lm(y~x), col="green")
>
>"mois" being a grouping variable and ID (see below) the 
>conditioning variable in a data.frame of 230 rows
>
>After several really disatreous trials, I have tried the following:
>
>xyplot(y~x|ID,panel=function(x,y){panel.superpose(x,y,subscript
>s=1:230,groups=mois);panel.abline(lm(y~x),col="green")})
>

You don't need to mess around with the subscripts argument for this. I think
the problem is that you are not passing the necessary graphical parameters
to your panel function. You could do:

dat <- expand.grid(ID = 1:4, mois = c(3, 9))
dat <- dat[rep(seq(nrow(dat)), rep(10, nrow(dat))), ]
dat <- data.frame(dat, x = rnorm(nrow(dat)), y = rnorm(nrow(dat)))
dat$ID <- factor(dat$ID)

lset(list(superpose.symbol = list(col = c("blue", "red"), pch = c(1, 1))))

xyplot(y ~ x | ID, data = dat,
       groups = mois,
       panel = function(x, y, ...) {
         panel.superpose(x, y, ...)
         panel.abline(lm(y~x), col = "green")
       })

Cheers,
Jim 

James A. Rogers 
Manager, Biometrics
PGR&D Groton Labs
Eastern Point Road (MS 8260-1331)
Groton, CT 06340
office: (860) 686-0786
fax: (860) 715-5445
 


LEGAL NOTICE\ Unless expressly stated otherwise, this messag...{{dropped}}




More information about the R-help mailing list