Bliese, Paul D MAJ WRAIR-Wash DC
2003-Feb-28 22:10 UTC
[R] lattice and fitted function error
Platform: WIN2000 Version of R: 1.6.2 I'm interested in plotting fitted values in a trellis xyplot. I believe the following should work; however, I only get the points (not the fitted lines). library(lattice) trellis.device(bg="white") xyplot(MULTDV~TIME|SUBNUM,data=TEMP, panel=function(x,y){ panel.xyplot(x,y) lines(x,fitted(lm(y~poly(x,1),na.action=na.omit))) lines(x,fitted(lm(y~poly(x,2),na.action=na.omit)),lty=3)}, xlab="Time", ylab="Average Reaction Time") Happy to send the very small TEMP file for the curious... Any suggestions? Paul MAJ Paul Bliese, Ph.D. Walter Reed Army Institute of Research Phone: (301) 319-9873 Fax: (301) 319-9484 paul.bliese at na.amedd.army.mil
Paul, I don't think you can use lines with trellis graphics. Check out ?panel.lmline (and other associated panel. functions). HTH steve "Bliese, Paul D MAJ WRAIR-Wash DC" wrote:> Platform: WIN2000 > Version of R: 1.6.2 > > I'm interested in plotting fitted values in a trellis xyplot. I believe the > following should work; however, I only get the points (not the fitted > lines). > > library(lattice) > trellis.device(bg="white") > > xyplot(MULTDV~TIME|SUBNUM,data=TEMP, > panel=function(x,y){ > panel.xyplot(x,y) > lines(x,fitted(lm(y~poly(x,1),na.action=na.omit))) > lines(x,fitted(lm(y~poly(x,2),na.action=na.omit)),lty=3)}, > xlab="Time", > ylab="Average Reaction Time") > > Happy to send the very small TEMP file for the curious... > > Any suggestions? > > Paul > > MAJ Paul Bliese, Ph.D. > Walter Reed Army Institute of Research > Phone: (301) 319-9873 > Fax: (301) 319-9484 > paul.bliese at na.amedd.army.mil > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help
You need to use llines instead of lines (lines doesn't produce any output with grid graphics). Quoting "Bliese, Paul D MAJ WRAIR-Wash DC" <Paul.Bliese at NA.AMEDD.ARMY.MIL>:> Platform: WIN2000 > Version of R: 1.6.2 > > I'm interested in plotting fitted values in a trellis xyplot. I believe > the > following should work; however, I only get the points (not the fitted > lines). > > library(lattice) > trellis.device(bg="white") > > xyplot(MULTDV~TIME|SUBNUM,data=TEMP, > panel=function(x,y){ > panel.xyplot(x,y) > lines(x,fitted(lm(y~poly(x,1),na.action=na.omit))) > lines(x,fitted(lm(y~poly(x,2),na.action=na.omit)),lty=3)}, > xlab="Time", > ylab="Average Reaction Time") > > Happy to send the very small TEMP file for the curious... > > Any suggestions? > > Paul > > MAJ Paul Bliese, Ph.D. > Walter Reed Army Institute of Research > Phone: (301) 319-9873 > Fax: (301) 319-9484 > paul.bliese at na.amedd.army.mil > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help >