Dear ExpeRts,
I am trying to plot a bunch of growth curves and would like to get
some more control over groups and line colors than I seem to have.
Example:
# make some data
dat <- Orange
dat$group <- ifelse(dat$Tree%in%c('1','4','5'),
'A', 'B')
# plot
xyplot(circumference~age, dat, groups=group)
# now use lines to make the growth curve more visible
xyplot(circumference~age, dat, groups=group, type='l')
# ugly, because of the 'return' lines
# to fix this set groups to Tree
xyplot(circumference~age, dat, groups=Tree, type='l')
# better, but now each Tree has its own color
Of course I can now use the col argument to manually assign the colors
by group but is there a more elegant way that I missed?
cu
Philipp
--
Dr. Philipp Pagel
Lehrstuhl f?r Genomorientierte Bioinformatik
Technische Universit?t M?nchen
Wissenschaftszentrum Weihenstephan
Maximus-von-Imhof-Forum 3
85354 Freising, Germany
http://webclu.bio.wzw.tum.de/~pagel/
On Apr 8, 2011, at 8:06 AM, Philipp Pagel wrote:> > Dear ExpeRts, > > I am trying to plot a bunch of growth curves and would like to get > some more control over groups and line colors than I seem to have. > > Example: > > # make some data > dat <- Orange > dat$group <- ifelse(dat$Tree%in%c('1','4','5'), 'A', 'B') > > # plot > xyplot(circumference~age, dat, groups=group) > > # now use lines to make the growth curve more visible > xyplot(circumference~age, dat, groups=group, type='l') > # ugly, because of the 'return' lines > > # to fix this set groups to Tree > xyplot(circumference~age, dat, groups=Tree, type='l') > # better, but now each Tree has its own color > > Of course I can now use the col argument to manually assign the colors > by group but is there a more elegant way that I missed?You aren't saying what you want but I am guessing it is a color-less plot: xyplot(circumference~age, dat, groups=Tree, type='l', par.settings=simpleTheme(col="grey")) trellis.par.set can also be used to specify this globally. -- David Winsemius, MD West Hartford, CT
Philipp,
I would do the following with ggplot2:
# Set up data
require(ggplot2)
dat <- Orange
dat$group <- ifelse(dat$Tree%in%c('1','4','5'),
'A', 'B')
# Specify the ggplot group aesthetic as Tree
g1 <- ggplot(data = dat, aes(x = age, y = circumference, group=Tree))
# Specify the geom_point and geom_line colour aesthetics as group
g1 + geom_point(aes(colour = group)) + geom_line(aes(colour = group))
Is this what you are after?
Jeremy
Jeremy Hetzel
Boston University
[[alternative HTML version deleted]]
Hi:
This seems to 'work':
xyplot(circumference~age, dat, groups=Tree, type='l',
col.line = c('red', 'blue', 'blue',
'red', 'red'))
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))
The problem with group is that it's character, so it can't be used to
assign
colors. However, if we convert it to factor with colors as labels...
Dennis
On Fri, Apr 8, 2011 at 5:06 AM, Philipp Pagel <p.pagel@wzw.tum.de> wrote:
>
> Dear ExpeRts,
>
> I am trying to plot a bunch of growth curves and would like to get
> some more control over groups and line colors than I seem to have.
>
> Example:
>
> # make some data
> dat <- Orange
> dat$group <- ifelse(dat$Tree%in%c('1','4','5'),
'A', 'B')
>
> # plot
> xyplot(circumference~age, dat, groups=group)
>
> # now use lines to make the growth curve more visible
> xyplot(circumference~age, dat, groups=group, type='l')
> # ugly, because of the 'return' lines
>
> # to fix this set groups to Tree
> xyplot(circumference~age, dat, groups=Tree, type='l')
> # better, but now each Tree has its own color
>
> Of course I can now use the col argument to manually assign the colors
> by group but is there a more elegant way that I missed?
>
> cu
> Philipp
>
> --
> Dr. Philipp Pagel
> Lehrstuhl für Genomorientierte Bioinformatik
> Technische Universität München
> Wissenschaftszentrum Weihenstephan
> Maximus-von-Imhof-Forum 3
> 85354 Freising, Germany
> http://webclu.bio.wzw.tum.de/~pagel/
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]