Re: [R] setting specific colours for different groups of points on a scatter plot

From: Petr PIKAL <petr.pikal_at_precheza.cz>
Date: Mon, 26 May 2008 10:19:26 +0200

Hi

if you do not insist on lattice you can

plot(a~b, col = c+1) or if you do not like built colours

mycol <- c("blue", "red", "green", "whatever") plot(a~b, col = mycol[c+1])

Petr Pikal
petr.pikal_at_precheza.cz
724008364, 581252140, 581252257

r-help-bounces_at_r-project.org napsal dne 22.05.2008 21:04:02:

> On 5/22/08, Sarah Kinnings <bssk@leeds.ac.uk> wrote:
> > Hi,
> >
> > I have a table with three columns of data, let's call these a, b and
c. I
> > have produced a scatter plot of a against b, but I would like to
colour the
> > points according to their corresponding c values. c takes the value of
> > either 0,1,2,3 or 4 and so I would like to colour all of the points
with a c
> > value of 0 one colour, all those with a c value of 1 another colour
etc.
> > When I use the following code, it colours the points using default
colours,
> > which are not suitable:
> >
> > data<-read.table('abc',header=T, sep="\t")
> > attach(data)
> > library(lattice)
> > xyplot(a~b, col=c)
> >
> > I was therefore wondering how to specify my own set of colours for
each of
> > the c values. Any help would really be appreciated as I have spent
ages
> > reading through the documentation, but with no luck.
>
> The recommended way would be
>
> mydata<-read.table('abc',header=T, sep="\t") # don't attach
> library(lattice)
> xyplot(a~b, data = mydata, groups=c)
>
> This would use the default lattice colors (which should be different
> from the ones you saw). If you don't like them, you could specify your
> own colors with
>
> mycol <- c("blue", "red", "green", "whatever")
> xyplot(a~b, data = mydata, groups=c, col = mycol)
>
> You will probably end up wanting a legend, in which case a better
approach is
>
> xyplot(a~b, data = mydata, groups=c,
> par.settings = simpleTheme(col = mycol),
> auto.key = TRUE)
>
> -Deepayan
>
> ______________________________________________
> R-help_at_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.



R-help_at_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. Received on Mon 26 May 2008 - 08:29:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 26 May 2008 - 08:30:41 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive