[R] lattice, different plotting symbols

Deepayan Sarkar deepayan at stat.wisc.edu
Fri Mar 5 00:21:23 CET 2004


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




More information about the R-help mailing list