[R] Multi-line plots with matrices in R
Petr Pikal
petr.pikal at precheza.cz
Wed Mar 7 14:02:59 CET 2007
Hi
see matplot, matlines.
or use forbidden for cycle.
for (i in 1:n) lines(x,y[,i], col=i)
or if you want to use more colours use built in rainbow, topo.colors
or generate your own set.
Regards
Petr
On 7 Mar 2007 at 12:30, Joseph Wakeling wrote:
Date sent: Wed, 07 Mar 2007 12:30:46 +0000
From: Joseph Wakeling <joseph.wakeling at webdrake.net>
To: r-help at stat.math.ethz.ch
Subject: [R] Multi-line plots with matrices in R
> 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
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
Petr Pikal
petr.pikal at precheza.cz
More information about the R-help
mailing list