I want to plot a large number of line segments, with a color associated with each line segment (I'm actually plotting a function of the edges of a 2d graph, and I want to use color to indicate the level of the function.) I originally thought I could use lines, but lines puts all its lines in one color (from help(lines), "col: color to use. This can be vector of length greater than one, but only the first value will be used."). Is there a function that does what I want? Right now I'm using the obvious solution of calling lines in a loop with a single segment, but this is really quite slow for my purposes, as I have several thousand lines total to plot. Cheers, rif
rif <rif at MIT.EDU> writes:> I want to plot a large number of line segments, with a color > associated with each line segment[snip]> Is there a function that does what I want? Right now I'm using the > obvious solution of calling lines in a loop with a single segment, but > this is really quite slow for my purposes, as I have several thousand > lines total to plot.I don't know how to break this to you, but.... Have you considered segments()?> plot(1:10,1:10) > segments(1:9,1:9,2:10,2:10,col=1:9,lwd=3)-- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
On Fri, 2004-07-02 at 16:33, rif wrote:> I want to plot a large number of line segments, with a color > associated with each line segment (I'm actually plotting a function of > the edges of a 2d graph, and I want to use color to indicate the level > of the function.) I originally thought I could use lines, but lines > puts all its lines in one color (from help(lines), "col: color to use. > This can be vector of length greater than one, but only the first > value will be used."). > > Is there a function that does what I want? Right now I'm using the > obvious solution of calling lines in a loop with a single segment, but > this is really quite slow for my purposes, as I have several thousand > lines total to plot.Take a look at ?matplot or ?matlines depending upon which one might make sense for your particular application. Both functions are on the same help page. HTH, Marc Schwartz
?segments url: www.econ.uiuc.edu/~roger Roger Koenker email rkoenker at uiuc.edu Department of Economics vox: 217-333-4558 University of Illinois fax: 217-244-6678 Champaign, IL 61820 On Jul 2, 2004, at 4:33 PM, rif wrote:> > I want to plot a large number of line segments, with a color > associated with each line segment (I'm actually plotting a function of > the edges of a 2d graph, and I want to use color to indicate the level > of the function.) I originally thought I could use lines, but lines > puts all its lines in one color (from help(lines), "col: color to use. > This can be vector of length greater than one, but only the first > value will be used."). > > Is there a function that does what I want? Right now I'm using the > obvious solution of calling lines in a loop with a single segment, but > this is really quite slow for my purposes, as I have several thousand > lines total to plot. > > Cheers, > > rif > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html