[R] Multiple plots in one screen

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sun Jan 16 12:15:55 CET 2005


Robert Weenink <robertweenink at planet.nl> writes:

> I'm a fairly new user of R and I'm confronted with a problem to which I can't find the solution in any R manual or FAQ.
> 
> I'd like to plot multiple 'graphs' in one plot screen. For example, my data frame would be:
> 
> x     a      b      c
> 1    11    15    18
> 2    26    12    19
> 3    22    17    14
> 
> And I'd like to plot a, b and c against x at the same time in one plot screen.
> 
> How is this done?

With matplot(). There are various possibilities, e.g.

> dd <- read.table(stdin(),header=TRUE)
0: x     a      b      c
1: 1    11    15    18
2: 2    26    12    19
3: 3    22    17    14
4: >
> matplot(dd$x,dd[-1],type="b")

(and you don't actually need the dd$x bit because it will plot against
the index if no x is given).

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




More information about the R-help mailing list