[R] Xyplot - adding model lines to plotted points
Sandeman, L. R.
l.sandeman at abdn.ac.uk
Thu Aug 2 16:16:20 CEST 2007
Hello,
I have written code to plot an xyplot as follows:
library(lattice)
xyplot(len~ageJan1|as.factor(cohort),groups=sex,as.table=T,strip=strip.c
ustom(bg='white',fg='white'),data=dat,
xlab="Age (January 1st)",ylab="Length (cm)",main="Linear models for male
and female cod, by cohort",type='p',
lwd=1.5,auto.key=list(text=c("Male","Female"),points=F,rectangles=F,line
s=T))
I have fitted a linear model to the same data (for each sex in each
cohort(year)). I would like to add the fitted models to the existing
plot (one line for male and one for female, where each panel is a
separate cohort - as in the above code....). I also want to do this
with non-linear models if possible.
I have trawled R help, and it seems that panel.superpose may be one
method of attempting this, however, I am unable to produce any working
code.
My dataset is too large to put in as an example, but it is in the basic
form as below (where sex is 1 for male and 5 for female).
len age fitted_model cohort sex
1 24 2 30.05771 1977 1
2 31 3 36.64122 1977 1
3 22 2 27.73938 1978 1
4 34 3 36.64122 1977 1
5 22 2 27.73938 1978 1
6 31 3 36.64122 1977 1
7 34 3 36.64122 1977 1
8 28 2 27.73938 1978 1
9 23 2 27.73938 1978 1
10 24 2 27.73938 1978 1
11 25 2 27.73938 1978 1
Etc...
Any suggestions would be greatly appreciated,
Thankyou,
Lillian.
----------------------
Lillian Sandeman
PhD Student
Zoology Building
University of Aberdeen
Tillydrone Avenue
Aberdeen
Scotland
AB24 2TZ
Tel.: +44 (0)1224 272395
E-mail: l.sandeman at abdn.ac.uk
More information about the R-help
mailing list