[R] xYplot, lmline and abline

From: Daniel E. Bunker <deb37_at_columbia.edu>
Date: Wed 07 Jun 2006 - 01:10:34 EST


Dear All,

I need to produce a multi-panel plot where:

  1. groups within panels receive distinct symbols;
  2. a linear regression is fit to the entire panel, not the individual groups;
  3. a common abline is plotted in each panel.

Essentially I would like to merge the two plots below, but I can't seem to figure out how to call both lmline and abline, and also retain the grouping symbols.

In addition, I have not yet figured out how to place the 'Key()' in the empty grid cell.

Please see the example code below. Note that I am running R2.2.1 on windows.

Any help would be greatly appreciated.

Thanks for your time,

Dan

library(Hmisc)
windows(record=TRUE)

panelgrp=rep(LETTERS[1:3], 20)
sites=c(rep("d", 15), rep("e", 15), rep("f", 15), rep("g", 15))

data1=data.frame(panelgrp=factor(panelgrp), sites=factor(sites))
data1$pred=runif(60)
data1$resp=runif(60)

lmcoef=lm(resp~pred, data=data1[data1$panelgrp=="A",])

xYplot(resp~pred|panelgrp, groups=sites, data=data1, pch=c(1,2,3,4),

        abline=list(a=lmcoef$coefficients[1], b=lmcoef$coefficients[2], lty=2))

    Key()

xYplot(resp ~ pred|panelgrp, groups=sites, pch=c(1,2,3,4),

    data=data1,

       panel = function(x, y) {
        panel.xyplot(x,y)
           panel.lmline(x,y, span=1)
       }

    )
-- 
Daniel E. Bunker
BioMERGE Associate Director
Post-Doctoral Research Scientist
Columbia University
Department of Ecology, Evolution and Environmental Biology
1200 Amsterdam Avenue
New York, NY 10027-5557

deb37ATcolumbiaDOTedu
212-851-1888 phone
212-854-8188 fax

______________________________________________
R-help@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
Received on Wed Jun 07 01:26:52 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 07 Jun 2006 - 02:10:36 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.