[R] Help with multicolored points in one plot

Thomas Lumley tlumley at u.washington.edu
Thu Feb 26 17:36:51 CET 2004


On Thu, 26 Feb 2004, David Thibault wrote:

> Hello all,
>
> I have a situation where I'd like to plot points from multiple groups of
> data in one plot.  I'd like each group's points to be colored a different
> color.  I've seen people comment on how you can alternate colors by
> providing a range of colors and then it will loop through each color as it
> plots individual points.  However, that just goes by individual points and
> not by group.
>

Concatenate the groups into a single x vector and y vector, together with
a vector of group identifiers (eg  1,1,1,1,1,2,2,2,2,2,2,2,3,3), then

plot(y~x, col=group)

or to get more control

prettycolors<- c("forestgreen","goldenrod","sienna")

plot(y~x, col=prettycolors[group])

There are examples in demo(graphics).

	-thomas




More information about the R-help mailing list