[R] Multi-line plots with matrices in R

Joseph Wakeling joseph.wakeling at webdrake.net
Wed Mar 7 13:30:46 CET 2007


Hello all,

I'm a new user of R, experienced with Octave/MATLAB and therefore
struggling a bit with the new syntax.

One of the easy things in Octave or MATLAB is to plot multiple lines or
 sets of points by using a matrix where either the columns or the rows
contain the y-values to be plotted.  Both packages automatically give
each line/points their own unique colour, character etc.

I'm wondering how I get the same functionality in R.  For example, if X
is a vector of x-values and Y is a matrix whose rows contain the
y-values, I can do,

apply(Y,1,lines,x=X)

... but of course everything is all in black, with the same type of line
or points.  I'd like each line to have its own unique colour and/or style.

Another thing I'd like clarification on is the ability to update an
existing plot.  For example if I do,

plot.window(xlim=c(0,100),ylim=c(0,1))

and then after plotting data decide I want ylim=c(0,0.5), how do I
update the graphic?  A new plot.window() command does nothing.

Many thanks,

    -- Joe



More information about the R-help mailing list