[R] xyplot and abline

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Sep 17 17:36:36 CEST 2005


On Sat, 17 Sep 2005, Marc Bernard wrote:

> Dear All,
>
> I wonderif there is a simple way to draw  a regression line in  the xyplot:
> more specifically, let:
>
> age <- c(20:30, 31:40 )
> age.cut <- cut(age, breaks = 2 )
> y<- rnorm(20)
> x <- rnorm(20,4,1)
>
> xyplot(y  ~  x| age.cut, xlab="x", ylab="y")
>
> How to draw (in the plot given by xyplot)  the two regression lines (y ~ 
> x) corresponding to the two category of age.cut ?

Use a panel function and call panel.lmline from it. Something like

mypanel <- function (x, y, ...)
{
    panel.xyplot(x,y, ...)
    panel.lmline(x,y, ...)
}

xyplot(y  ~  x| age.cut, xlab="x", ylab="y", panel=mypanel)

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list