Re: [R] Multiple line plots

From: Marc Schwartz <MSchwartz_at_mn.rr.com>
Date: Thu 16 Jun 2005 - 05:12:32 EST

On Wed, 2005-06-15 at 13:50 -0500, Mihai Nica 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
>
> Thanks,
>
> Mihai

# First argument is x axis vector
# Second argument is the y value vectors

matplot(df$Year, df[, -1], type = "l", xlab = "Year",

        ylab = "Some Unit of Measure")

If you want a legend, you could use the following:

legend(1985, 150, legend = colnames(df)[-1], lty = 1:3, col = 1:3)

See ?legend as well.

HTH, Marc Schwartz



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 06:20:29 2005

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