Re: [R] Multiple lines with a different color assigned to each line (corrected code)

From: Jim Lemon <>
Date: Wed, 27 Feb 2008 20:35:55 +1100

Judith Flores wrote:
> Sorry, I just realized I didn't type in the correct
> names of the variables I am working with, this is how
> it should be:
> plot(1,1,type="n")
> for (i in summ$tx) {
> points(summ$timep[summ$tx==i],summ$mn[summ$tx==i])
> lines(summ$timep[summ$tx==i],summ$mn[summ$tx==i])
> }
Hi Judith,

I think this might help:

# define your colors here
# you can generate the vector in many ways ncolors<-length(unique(summ$tx))
for(i in summ$tx) {
  points(summ$timep[summ$tx==1],summ$mn[summ$tx==i],    type="b",col=colorvector[colorindex])   colorindex<-colorindex+1

This may also answer the query from Valentin Bellassen.

Jim mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed 27 Feb 2008 - 09:31:41 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 Wed 27 Feb 2008 - 10:30:17 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive