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.dfyear 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? Thanks. ---------------------------------------------------------------------- Andrew J Perrin - andrew_perrin at 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 at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 at 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 at 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 at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Fri, 8 Feb 2002, 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 > > 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? >Following is an example of such a graph. Save the data below into a file 'loan.tab'. Then run the example code that appears below the data. By the way, this example comes from an R package called "intrograph" (a package of examples designed to introduce R graphics to new users) that should be shortly making its debut on CRAN. --Landon Sego num adjmon newrate oldrate fixedrate paid 1 Jan-00 8.09091 7.33541 8.250 0.23 2 Feb-00 8.20139 7.20833 8.375 0.17 3 Mar-00 7.90457 8.03989 8.250 0.49 4 Apr-00 8.22500 7.34167 8.250 0.20 5 May-00 8.41346 7.35577 8.375 0.08 6 Jun-00 8.75000 7.52273 8.500 0.27 7 Jul-00 8.54348 8.70109 8.250 0.00 8 Aug-00 8.61923 7.44231 8.125 0.08 ## Example: group.plotting loan <- read.table(file='loan.tab',header=T) attach(loan) par(las=1) # Notice how "type='n'" allows us to custom plot the lines and characters for # different groups individually plot(num,newrate,type='n',main='Comparison of Interest Rates', xlab='Adjustment Month',ylab='Average Interest Rate',ylim=c(6.7,9.2)) # Plot the fixed rate curve and points points(num,fixedrate,pch='F') lines(num,fixedrate,lty=1) # Plot the new rate curve and points points(num,newrate,pch='N') lines(num,newrate,lty=3) # Plot the oldrate curve and points points(num,oldrate,pch='O') lines(num,oldrate,lty=2) # Replot the horizontal axis axis(1,1:8,col.axis='white') axis(1,1:8,labels=c('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug'),cex=1.2) # Add descriptive text text(4.5,6.85,'Percentage of loans paid off:') text(num,rep(6.7,8),c('23\%','17\%','49\%','25\%','14\%','27\%','0\%','20\%')) # Add legend legend(.8,9.25,c('Fixedrate','Newrate','Oldrate'),lty=c(1,3,2)) # Detach the loan data set from the search path detach() -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Andrew, What about preprocessing the dataset to remove NAs? eomit<-na.omit(efficacy.df) attach(eomit) rs<-cbind(complicated, havesay, dontcare) matplot(year, rs) matlines(year, rs) Scot -- Scot W. McNary email:smcnary at charm.net On Fri, 8 Feb 2002, 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? > > Thanks. > > ---------------------------------------------------------------------- > Andrew J Perrin - andrew_perrin at 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 at 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 at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._