[R] 2 different colors for 2 groups of lines using xyplot

Dieter Menne dieter.menne at menne-biomed.de
Thu Feb 12 08:36:38 CET 2009


Yu, Xuesong <xyu <at> scharp.org> writes:

> I am trying to use xyplot to plot several lines in one panel with red
> color  for a group of lines, say 3 lines and blue color for another
> group of lines, say 4. I know this can be easily  done using regular
> plot function. But i could not figure out how to do this in xyplot. 
> 

states <- data.frame(state.x77,
                     state.name = dimnames(state.x77)[[1]], 
                     state.region = state.region) 
xyplot(Murder ~ Population, data = states, 
       groups = state.region,
       col.line=c("red","red","green","green"),
       panel = panel.superpose,
       panel.groups = panel.loess)
# Note the difference when colors are recycled        
xyplot(Murder ~ Population, data = states, 
       groups = state.region,
       col.line=c("red","green"),
       panel = panel.superpose,
       panel.groups = panel.loess)
        
  
Dieter




More information about the R-help mailing list