[R] coloring individual points in lattice xyplot

Gabor Grothendieck ggrothendieck at gmail.com
Tue Jul 4 20:31:49 CEST 2006


On 7/4/06, Deepayan Sarkar <deepayan.sarkar at gmail.com> wrote:
> On 7/4/06, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> > If I wish to color groups in xyplot I can do this:
> >
> >    library(lattice)
> >    x <- 1:10
> >    y <- cbind(x, x+1)
> >    xyplot(y ~ rep(x,2), group = col(y), col = 1:2)
> >
> > How do I color different points differently within a group.
> >
> > For example, I want to produce this plot (except that I only
> > want to have two groups, not 11):
> >
> >    xyplot(y ~ rep(x,2), group = c(rep(1, 10), 2:11), col = 1:11)
> >
> > I am thinking of something like this (although
> > this does not work, its just to get the idea across):
> >
> >    xyplot(y ~ rep(x,2), group = col(y), col = list(1, 2:11))
> >
> > where, in general, I have a list with one component per group
> > whose elements are scalars to color the whole group or
> > vectors one color per point in the group.  I don't know
> > ahead of time what the list is.
> >
> > I am looking for a general approach to this within the lattice
> > xyplot plot framework; the above is just an example.
>
> The general approach is to write your own panel function. For a
> possible template, look at the functions panel.superpose and
> panel.superpose.2 and how they handle the 'type' argument.
>
> Deepayan
>

There is no example in ?panel.superpose.  Do you think you
could provide an example for the situation in my post?

I have done quite a bit of RSiteSearch'ing and googling prior to
posting and all the examples I found had colors that depended
on the group, none addressed the situation in my post -- i.e.
coloring individual points within groups.



More information about the R-help mailing list