[R] Plot of multiple data sets

Stéphane Mattei stephane.mattei at epfl.ch
Wed Sep 7 16:24:58 CEST 2005


Selon Gabor Grothendieck <ggrothendieck at gmail.com>:

> On 9/7/05, Stéphane Mattei <stephane.mattei at epfl.ch> wrote:
> > Hello !
> >
> >
> > There is something quite simple I want to do with R but I found nowhere in the help how to do
> it.
> > I just want to plot data which are in a matrix, every column being a data set and having the
> same
> > x-axis (just an index).
> >
> > So for example if I have a 50 x 6 matrix I want 6 set of points on the same plot.
> >
> > I tried
> > plot,new()
> > plot(MATRIX[,1])
> > plot(MATRIX[,2])
> > ...
> >
> > but it replaces the previous plot each time.
>
> Others have already mentioned matplot, lines and points but just to add
> to the list, if your problem is a time series then you could also use
> plot.zoo:
> library(zoo)
> z <- zoo(MATRIX, x)
> plot(z, plot.type ="single")  # one plot
> plot(z) # separate plots
>
Thank you very much Gabor!
Your solution is best because with points it doesn't adapt the axis. But it's funny it needs an
extra-package for such a simple thing ! I thought that could be done with just the plot command




More information about the R-help mailing list