[R] Alternative to xyplot()?

Ben Bolker bolker at ufl.edu
Wed Jul 18 03:13:51 CEST 2007


Manuel Morales <Manuel.A.Morales <at> williams.edu> writes:

> 
> Sorry. I was thinking of the "groups" functionality, as illustrated
> below:
> 
> grps<-rep(c(1:3),10)
> x<-rep(c(1:10),3)
> y<-x+grps+rnorm(30)
> library(lattice)
> xyplot(y~x,group=grps, type=c("r","p"))

  The points (type "p") are easy, the regression lines (type "r") are a little
harder. How about:


plot(y~x,col=grps)
invisible(mapply(function(z,col) {abline(lm(y~x,data=z),col=col)},
          split(data.frame(x,y),grps),1:3))

  cheers
    Ben Bolker



More information about the R-help mailing list