Hello, I would like to get a lattice plot of 8 panels (unique(df$fact)=8) with 2 graphs (df$y1 and df$y2 as a function of df$x) and 1 red point at (500, ymax) per panel. The script below is quite ok but I'm not able to define two different colors for the two graphs. If you have an idea how to use the "col" function in order to attribute the colors, it will be very kind of you to share it with a newbie. Have a nice week-end, Ptit Bleu. x11(15,12) xyplot(df$y1 + df$y1/df$coeff ~ df$x | df$fact, panel = function(x, y) { panel.grid(h=-1, v=-1, col="gray") panel.xyplot(x, y, type="p", pch=20) panel.points(500, ymax[panel.number()], col="red", pch=20, cex=1.6) }, xlab="X", ylab="Y") -- View this message in context: http://n4.nabble.com/lattice-2-graphs-per-panel-with-2-differents-colours-tp961037p961037.html Sent from the R help mailing list archive at Nabble.com.
S Devriese
2009-Dec-13 12:04 UTC
[R] lattice - 2 graphs per panel with 2 differents colours
On 12/11/2009 02:03 PM, PtitBleu wrote:> Hello, > > I would like to get a lattice plot of 8 panels (unique(df$fact)=8) with 2 > graphs (df$y1 and df$y2 as a function of df$x) and 1 red point at (500, > ymax) per panel. > > The script below is quite ok but I'm not able to define two different colors > for the two graphs. > If you have an idea how to use the "col" function in order to attribute the > colors, it will be very kind of you to share it with a newbie. > > Have a nice week-end, > Ptit Bleu. > > > x11(15,12) > xyplot(df$y1 + df$y1/df$coeff ~ df$x | df$fact, > panel = function(x, y) { > panel.grid(h=-1, v=-1, col="gray") > panel.xyplot(x, y, type="p", pch=20) > panel.points(500, ymax[panel.number()], col="red", pch=20, > cex=1.6) > }, > xlab="X", ylab="Y") > >If you add '...' to your panel function, it will allow the panel function to use the info you did not provide explicitly: panel = function(x, y, ...) { panel.grid(h=-1, v=-1, col="gray") panel.xyplot(x, y, type="p", pch=20, ...) panel.points(500, ymax[panel.number()], col="red", pch=20, cex=1.6) }, I tested with: library(lattice) tmp <- data.frame(y1=11:20,coeff=1:10,x1=21:30) xyplot(y1 + y1/coeff ~ x1, data=tmp, panel=function(x,y,...) { panel.xyplot(x, y, type="p", pch=20, ...) } ) Stephan