Dimitris Rizopoulos <dimitris.rizopoulos <at> med.kuleuven.be> writes: > > the 'col' argument of plot() may also be a vector, e.g., > > x <- sort(rnorm(15)) > y <- rnorm(15) > plot(x, y, > col = rep(c("red", "blue", "magenta"), c(5, 6, 4)))
> Dimitris > > ---- > Dimitris Rizopoulos > > ----- Original Message ----- > From: "mysimbaa" <adel.tekari <at> sisltd.ch> > To: <r-help <at> r-project.org> > Sent: Tuesday, November 13, 2007 9:46 AM > Subject: [R] Plot segments with different colors > > > > > Hello Everybody, > > I'm trying to plot(x,y) using different colors. > > I have to cut (x,y) into sub intervals. > > And I want to plot this sub intervals using colors. But infortunally > > I don't > > know how to do this with R. > > Can any body help me please? > > > > My code is looking like : > > x<-c(tvar[1:t0],tvar[t0:(ts)],tvar[ts:n]) > > F<-c(var[1:t0],var[t0:(ts)],var[ts:n]) > > plot(x,F,xlab="Zeit [s]",ylab="Variation [%]",col = "red",type="l") That works great for points but if you want to vary the properties of segments of lines, then you need the segments() function. x <- 1:3 y <- c(1, 5, 2) plot(x, y) segments(x[1:2], y[1:2], x[2:3], y[2:3], col = c("blue", "red"), lwd = c(1, 4), lty = 1:2) > > Thanks > > -- best, Ken ______________________________________________ R-help@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.