[R] Alternative to xyplot()?

Stephen Tucker brown_emu at yahoo.com
Wed Jul 18 05:49:14 CEST 2007


What's wrong with lattice? Here's an alternative:

library(ggplot2)
ggplot(data=data.frame(x,y,grps=factor(grps)), 
       mapping=aes(x=x,y=y,colour=grps)) +     # define data
  geom_identity() +                            # points
  geom_smooth(method="lm")                     # regression line



--- Ben Bolker <bolker at ufl.edu> wrote:

> 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
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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