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 ? Thanks a lot, Bernard --------------------------------- [[alternative HTML version deleted]]
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
> I wonderif there is a simple way to draw a regression line in the xyplot:Try: xyplot(y ~ x| age.cut, xlab="x", ylab="y", type=c("p","r")) Hadley
How should I pass abline to this function so that I get a reference line
at h=0 in each panel?
sps <- trellis.par.get("superpose.symbol")
sps$pch <- 1:10
trellis.par.set("superpose.symbol",sps)
xyplot(fcast$LOGDIFF~fcast$VINTAGE|fcast$REGION,
groups=fcast$LAG,
panel=panel.superpose,
type="b",mfcol=c(3,5),
key=list(columns=3,
text=list(paste(c("forecast: ", "",""),
unique(fcast$LAG), "years")),
points=Rows(sps,1:3)))
Cheers,
JC
On Thu, 2005-09-22 at 10:35 +0200, Vincent.Duval at bc.boehringer-ingelheim.com wrote:> Use panel.superpose into a panel function > Here is some changes in your function that should do the work, > I haven't tried it but at least it should be closed to it, > HTH > Vincent >Perfect. Thank you.> Suggestions > xyplot(fcast$LOGDIFF~fcast$VINTAGE|fcast$REGION, > groups=fcast$LAG, > type="b",mfcol=c(3,5), > panel=function(x,y,...){ > panel.superpose(x,y,...) > panel.abline(h=0) > }, > key=list(columns=3, > text=list(paste(c("forecast: ", "",""), > unique(fcast$LAG), "years")), > points=Rows(sps,1:3))) > > -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of John Charles > Considine > Sent: Thursday, September 22, 2005 10:11 AM > To: r-help > Subject: [R] xyplot and abline > > > "MMS - ING02 <ing.boehringer-ingelheim.com>" made the following annotations. > ===========================================================================> => "This e-mail was identified as a newsletter. Please decide if this e-mail > is of business relevance, if it is not, please delete it. Thank you". > ===========================================================================> => > How should I pass abline to this function so that I get a reference line > at h=0 in each panel? > > sps <- trellis.par.get("superpose.symbol") > sps$pch <- 1:10 > trellis.par.set("superpose.symbol",sps) > xyplot(fcast$LOGDIFF~fcast$VINTAGE|fcast$REGION, > groups=fcast$LAG, > panel=panel.superpose, > type="b",mfcol=c(3,5), > key=list(columns=3, > text=list(paste(c("forecast: ", "",""), > unique(fcast$LAG), "years")), > points=Rows(sps,1:3))) > > Cheers, > > JC > > ______________________________________________ > 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