[R] impose points on lattice plot
R-help, I'm using the lattice package to plot 2 variables (vekt ~ aldur) conditioned to a third (kyn * 2 categories). I use the following: xyplot(vekt ~ aldur|kyn, , data = sexSu) I want to superimpose the average(vekt) by 'aldur' conditioned to kyn by using something like: xyplot(vekt~aldur|kyn, subset = aldur = 12 , data = sexSu, panel = function(x, y) { panel.xyplot(x, y) panel.points(x,mean(y),col=2,cex=2 ) }) but th output is just a horozontal line ( the average of 'vekt') in both panels I guess) How can be done? Thanks in advance version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 4.1 year 2006 month 12 day18 svn rev40228 language R version.string R version 2.4.1 (2006-12-18) __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] impose points on lattice plot
Luis Ridao Cruz said the following on 3/27/2007 6:15 AM: R-help, I'm using the lattice package to plot 2 variables (vekt ~ aldur) conditioned to a third (kyn * 2 categories). I use the following: xyplot(vekt ~ aldur|kyn, , data = sexSu) I want to superimpose the average(vekt) by 'aldur' conditioned to kyn by using something like: xyplot(vekt~aldur|kyn, subset = aldur = 12 , data = sexSu, panel = function(x, y) { panel.xyplot(x, y) panel.points(x,mean(y),col=2,cex=2 ) }) but th output is just a horozontal line ( the average of 'vekt') in both panels I guess) How can be done? An working example would be nice. But here's one possible solution if I understand your question correctly: xyplot(vekt~aldur|kyn, subset = aldur = 12 , data = sexSu, panel = function(x, y) { panel.xyplot(x, y) mx - sort(unique(x)) my - tapply(y, x, mean) o - order(mx) panel.points(mx[o],my[o],col=2,cex=2 ) }) but th output Thanks in advance version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 4.1 year 2006 month 12 day18 svn rev40228 language R version.string R version 2.4.1 (2006-12-18) __ 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 and provide commented, minimal, self-contained, reproducible code. __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] impose points on lattice plot
On 3/27/07, Sundar Dorai-Raj [EMAIL PROTECTED] wrote: Luis Ridao Cruz said the following on 3/27/2007 6:15 AM: R-help, I'm using the lattice package to plot 2 variables (vekt ~ aldur) conditioned to a third (kyn * 2 categories). I use the following: xyplot(vekt ~ aldur|kyn, , data = sexSu) I want to superimpose the average(vekt) by 'aldur' conditioned to kyn by using something like: xyplot(vekt~aldur|kyn, subset = aldur = 12 , data = sexSu, panel = function(x, y) { panel.xyplot(x, y) panel.points(x,mean(y),col=2,cex=2 ) }) but th output is just a horozontal line ( the average of 'vekt') in both panels I guess) How can be done? An working example would be nice. But here's one possible solution if I understand your question correctly: xyplot(vekt~aldur|kyn, subset = aldur = 12 , data = sexSu, panel = function(x, y) { panel.xyplot(x, y) mx - sort(unique(x)) my - tapply(y, x, mean) o - order(mx) panel.points(mx[o],my[o],col=2,cex=2 ) }) Yes, and since this calculation is already implemented in 'panel.linejoin', you could alternatively try xyplot(vekt~aldur|kyn, subset = aldur = 12, data = sexSu, panel = function(x, y, ...) { panel.xyplot(x, y, ...) panel.linejoin(x, y, fun = mean, horizontal=FALSE, col = black) }) or even more conveniently (thanks to the 'type' argument in panel.xyplot), xyplot(vekt~aldur|kyn, subset = aldur = 12, data = sexSu, type = c(p, a)) -Deepayan __ 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 and provide commented, minimal, self-contained, reproducible code.