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,subscripts=1:230,groups=mois);panel.abline(lm(y~x),col="green")}) 1/ I am not sure to have well understood what the role of subscripts (with no default) is in the function panel.superpose and if the values passed are appropriate here; 2/ this apparently displays all the points without changes of style between groups (neither symbols or colors). 3/ this does not allow changes in color for points display Can anybody give me a hint on where I am wrong? Sorry to be probably very clumpsy, Kind regards, Patrick Giraudoux
Rogers, James A [PGRD Groton]
2004-Jan-14 13:00 UTC
[R] RE: Trellis graph and two colors display
>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}}