[R] xyplot, groups and colors

Philipp Pagel p.pagel at wzw.tum.de
Mon Apr 11 09:52:28 CEST 2011

On Fri, Apr 08, 2011 at 08:14:21AM -0700, Dennis Murphy wrote:

Thanks to everyone who replied! Especialy this and the ggplot advice
did what I wanted.

> xyplot(circumference~age, dat, groups=Tree, type='l',
>           col.line = c('red', 'blue', 'blue', 'red', 'red'))

This is essentially what I had been doing after somehow creating the
correct color vector.

> After a little more fiddling around, this also works, and seems a bit less
> kludgy:
> dat$group2 <- factor(dat$group, labels = c('red', 'blue'))
> xyplot(circumference~age, dat, groups=Tree, type='l',
>           col.line = levels(dat$group2))

Perfect! Using the levels directly had not occured to me. Thanks!


Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
Maximus-von-Imhof-Forum 3
85354 Freising, Germany

More information about the R-help mailing list