Skip to content

Plot of multiple data sets

7 messages · Stéphane Mattei, Duncan Murdoch, Henrik Andersson +3 more

#
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.


Thank you very much if you can help !
#
On 9/7/2005 9:28 AM, St??phane Mattei wrote:
See ?matplot.  For example,

matplot(1:10, cbind(rnorm(10),rnorm(10)), type='l')
#
Have a look at ?matplot
St??phane Mattei wrote:

  
    
#
Le 07.09.2005 15:28, St??phane Mattei a ??crit :
Hello Stephane,

there is a lot of solutions for your problem. It's up to you :

?matplot
?points
?lines
par(new=TRUE)
http://addictedtor.free.fr/graphiques/search.php?q=parallel

Good day.

Romain
#
On 9/7/05, St??phane Mattei <stephane.mattei at epfl.ch> wrote:
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
#
Selon Gabor Grothendieck <ggrothendieck at gmail.com>:
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
#
Hi

what is wrong with matplot

sines <- outer(1:20, 1:4, function(x, y) sin(x / 20 * pi * y))
matplot(sines, pch = 1:4, type = "o", col = rainbow(ncol(sines)))

so you can use aditional parameters to exactly specify what type of 
point and/or line and in what colour you will plot.

Or with plot/points construction you can adapt xlim and ylim 
setting to suite the whole plotting range e.g..

ddd<-dim(sines)[1] # length of x axis

plot(1:ddd,rep(1,ddd), type="n", ylim=range(sines)) # y in propper 
range

for (i in 1:4) points(1:ddd,sines[,i], pch = i, type = "b", col = 
rainbow(ncol(sines))[i]) # 4 columns plotted

If you want do more complicated things you usually has to use 
more complicated constructions.

BTW

help.search("plot column") goes stright to matplot and from its 
help page you could learn how to use it.

HTH
Petr
On 7 Sep 2005 at 16:24, St??phane Mattei wrote:

            
Petr Pikal
petr.pikal at precheza.cz