Re: [R] Plotting multiple columns on same graph

About this list Date view Thread view Subject view Author view Attachment view

From: Achim Zeileis (zeileis@ci.tuwien.ac.at)
Date: Sat 09 Feb 2002 - 08:00:56 EST


Message-id: <3C643C88.9C3823DB@ci.tuwien.ac.at>

Andrew Perrin wrote:
>
> I'd like to produce a series of simple line graphs for my methods class
> that show the three questions used on a repeated survey to make up a
> particular index. The data frame is:
>
> > efficacy.df
> year complicated havesay dontcare
> 1 1952 71 68 63
> 2 1954 NA NA NA
> 3 1956 64 71 71
> 4 1958 NA NA NA
> 5 1960 59 72 73
> 6 1962 NA NA NA
> 7 1964 67 70 62
> 8 1966 69 60 57
> 9 1968 71 58 55
> 10 1970 73 64 50
> 11 1972 74 59 49
> 12 1974 72 57 46
> 13 1976 70 56 44
> 14 1978 NA 53 45
> 15 1980 71 59 43
> 16 1982 NA 52 50
> 17 1984 70 68 57
> 18 1986 66 NA 43
> 19 1988 66 50 37
> 20 1990 65 34 23
> 21 1992 63 57 37
> 22 1994 73 34 22
> 23 1996 60 38 24
> 24 1998 71 46 25
> 25 2000 NA 50 33
>
> The ideal graph will show each of the three questions as a different
> color line, with lines connecting years spanned by NA values. What's the
> easiest way to do this?

Most of this can be done easily by plotting a multiple time series:

R> efficacy.mts <- ts(as.matrix(efficacy.df)[,2:4], start=1952)
R> plot(efficacy.mts, plot.type="single", col=1:3)

I'm not sure what is the easiest way to deal with the NAs. I would
probably interpolate the ts before plotting...
Hope that helps
Z

> Thanks.
>
> ----------------------------------------------------------------------
> Andrew J Perrin - andrew_perrin@unc.edu - http://www.unc.edu/~aperrin
> Assistant Professor of Sociology, U of North Carolina, Chapel Hill
> 269 Hamilton Hall, CB#3210, Chapel Hill, NC 27599-3210 USA
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Wed 16 Oct 2002 - 11:56:56 EST