Thanks, yes that does the trick, sorry inadvertently left the "tavg" in my example. I haven't used the panel function before looks like it maybe useful. Really appreciate your help.
regards Andrew McFadden MVS BVSc | Incursion Investigator (animals), Investigation and Diagnostic Centre | Biosecurity New Zealand Ministry of Agriculture and Forestry | 66 Ward St, Wallaceville | PO Box 40 742 | Upper Hutt | New Zealand Telephone: 64-4-894 5611 | Facsimile: 64-4-894 4973| Mobile: 027-733-1791 | Web: www.maf.govt.nz -----Original Message----- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: Monday, 15 February 2010 1:02 p.m. To: Andrew McFadden Cc: r-help@r-project.org Subject: [Requires Classification] Re: [R] Adding a regression line to an xyplot On Feb 14, 2010, at 6:33 PM, Andrew McFadden wrote: > Hi R users > >> I am trying to add a regression line to a graph for "c" for factor 2 >> only. Any suggestions? >> > library(lattice) > > a=(1:10) > b=c(1:5,16:20) > c=as.factor(c(rep(1,5),rep(2,5))) > > d=data.frame(a,b,c) > > xyplot(a~b, pch=c(6,8),data = tavg, groups=d$c, Seems likely that you want the dataframe defined above to be used as the argument to 'data='. Otherwise xyplot throws an error unless "tavg" is defined elsewhere. If so, then try: tavg=data.frame(a,b,c) xyplot(a~b, pch=c(6,8),data = tavg, groups=c, panel=function(x,y, groups,...) { panel.xyplot(x,y,groups,type=c("p"),...); panel.lmline(x[c=="2"],y[c=="2"],groups,...)}, xlab="a",ylab="b") > reg.line=lm, smooth=FALSE, type=c("p","g"),xlab="a",ylab="b") > >> I would appreciate your help. >> >> Kind regards >> >> andy >> >> Andrew McFadden MVS BVSc >> Incursion Investigator >> Investigation & Diagnostic Centres - Wallaceville Biosecurity New >> Zealand Ministry of Agriculture and Forestry >> >> Phone 04 894 5600 Fax 04 894 4973 Mobile 029 894 5611 Postal address: >> Investigation and Diagnostic Centre- Wallaceville Box 40742 Ward St >> Upper Hutt >> > > ###################################################################### > ## This email message and any attachment(s) is intended solely for the > addressee(s) named above. The information it contains is confidential > and may be legally privileged. Unauthorised use of the message, or > the information it contains, may be unlawful. If you have received > this message by mistake please call the sender immediately on 64 4 > 8940100 or notify us by return email and erase the original message > and attachments. Thank you. > > The Ministry of Agriculture and Forestry accepts no responsibility for > changes made to this email or to any attachments after transmission > from the office. > ###################################################################### > ## > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.