Judith Flores
2008-Feb-26 22:24 UTC
[R] Multiple lines with a different color assigned to each line (corrected code)
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]) } Thank you, Judith ____________________________________________________________________________________ Be a better friend, newshound, and
hadley wickham
2008-Feb-26 23:02 UTC
[R] Multiple lines with a different color assigned to each line (corrected code)
It's hard to provide a useful answer without know what your data looks like, but maybe something like: library(ggplot2) qplot(timep, mn, data=summ, geom="line", colour = tx) Hadley On Tue, Feb 26, 2008 at 4:24 PM, Judith Flores <juryef at yahoo.com> 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]) > } > > > Thank you, > > Judith > > > > ____________________________________________________________________________________ > Be a better friend, newshound, and > > ______________________________________________ > 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. >-- http://had.co.nz/
Jim Lemon
2008-Feb-27 09:35 UTC
[R] Multiple lines with a different color assigned to each line (corrected code)
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: plot(1,1,type="n") # define your colors here # you can generate the vector in many ways ncolors<-length(unique(summ$tx)) colorvector<-rainbow(ncolors) colorindex<-1 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