[R] xYplot, lmline and abline
Daniel E. Bunker
deb37 at columbia.edu
Tue Jun 6 17:10:34 CEST 2006
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
More information about the R-help
mailing list