Hi, I am trying to plot different variables from a data.frame using lattice's xyplot using code like that below. How do I specify a symbol and color for the variable 'prob' and different one's for 'll.prob'? Thanks, Matt xyplot( prob + ll.prob ~ time.eff |stat.id + time.out ,data = OUT, allow.multiple = TRUE, layout = c(6,3), as.table = TRUE , panel = function(x,y){panel.abline(h = 0) panel.xyplot(x,y)}, strip = TRUE, ) Matt Pocernich NCAR - Research Applications Program 303-497-8312
On Thursday 04 March 2004 14:28, Matt Pocernich wrote:> Hi, > > I am trying to plot different variables from a data.frame using > lattice's xyplot using code like that below. How do I specify a symbol > and color for the variable 'prob' and different one's for 'll.prob'? > > Thanks, Matt > > xyplot( prob + ll.prob ~ time.eff |stat.id + time.out ,data = OUT, > allow.multiple = TRUE, > layout = c(6,3), as.table = TRUE , > > panel = function(x,y){panel.abline(h = 0) > panel.xyplot(x,y)}, > strip = TRUE, > )What you are plotting is a grouped display (equivalent to having a non-trivial 'groups' argument), which means your panel function must be able to handle arguments called 'groups' and 'subscripts'. The standard panel function meant to be used for this is panel.superpose. This would be the default if you didn't specify a panel function, but since you also want a horizontal line, you need to do something like panel = function(x,y,...) { panel.abline(h = 0) panel.superpose(x,y,...) } (using ... is the easiest way to specify 'groups' and 'subscripts', you could also supply them explicitly.) This would use different symbols and colors obtained from the global lattice settings (as displayed by show.settings()), which you could override by explicitly specifying 'col' and 'pch' (for color and symbol respectively) to the xyplot call. (Both should be of length 2 in this case) Deepayan
Hi Matt,> I am trying to plot different variables from a data.frame using lattice's > xyplot using code like that below. How do I specify a symbol and color > for the variable 'prob' and different one's for 'll.prob'?I think you probably want to use panel.superpose instead of panel.xyplot. Behind the scenes xyplot is converting prob + ll.prob to groups - and panel.superpose knows how to plot different groups with different symbols. Normally xyplot changes the default panel from panel.xyplot to panel.superpose when you use that formula construct, but because you've specified your own panel function it can't. Hadley> > Thanks, Matt > > xyplot( prob + ll.prob ~ time.eff |stat.id + time.out ,data = OUT, > allow.multiple = TRUE, > layout = c(6,3), as.table = TRUE , > > panel = function(x,y){panel.abline(h = 0) > panel.xyplot(x,y)}, > strip = TRUE, > ) > > Matt Pocernich > NCAR - Research Applications Program > 303-497-8312 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html