Re: [R] Multiple line plots

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu 16 Jun 2005 - 10:15:55 EST

On 6/15/05, Mihai Nica <m_nica@hotmail.com> wrote:
> Greetings,
>
> I would like to plot three lines on the same figure, and I am lost. There is
> an answer to a similar threadů but I tried matplot and it is beyond me. An
> example of the data follows:
>
> Year EM IM BM
> 1983 9.1 16.8 -7.7
> 1984 12.0 18.0 -6.0
> 1985 13.6 19.1 -5.5
> 1986 12.4 17.3 -4.9
> 1987 14.6 20.3 -5.7
> 1988 20.6 23.3 -2.6
> 1989 25.0 27.2 -2.2
> 1990 28.4 30.2 -1.8
> 1991 33.3 31.2 2.1
> 1992 40.6 35.2 5.4
> 1993 41.6 39.9 1.7
> 1994 50.8 49.5 1.3
> 1995 46.3 61.7 -15.4
> 1996 56.8 73.0 -16.2
> 1997 71.4 85.9 -14.5
> 1998 79.0 94.7 -15.7
> 1999 87.0 109.7 -22.7
> 2000 111.7 135.9 -24.2
> 2001 101.5 131.4 -29.9
> 2002 97.5 134.6 -37.1
> 2003 97.4 138.1 -40.6
> 2004 110.8 155.8 -45.1
>

Suppose the data frame is dd. Then:

matplot(dd[,1], dd[,-1], type = "l")

Another possibility is to notice that this is a regularly spaced time series and it could be useful to represent it as a ts class object for here and for other purposes:

ddts <- ts(as.matrix(dd[,-1]), start = dd[1,1]) plot(ddts, plot.type = "single", col = 1:3)



R-help@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 Received on Thu Jun 16 10:21:24 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:43 EST