Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.LNX.4.61.0509171632140.23948@gannet.stats>
Date: 2005-09-17T15:36:36Z
From: Brian Ripley
Subject: xyplot and abline
In-Reply-To: <20050917150145.52245.qmail@web25805.mail.ukl.yahoo.com>

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