say we have:> x<-data.frame(a=c(1,2,3,4,5),b=c(1,1,1.5,2,2)) > y<-data.frame(a=c(1,2,3,4,5),b=c(1,2,2,3,3))How would I plot this so that, with the shared $a as the x-axis values, I have both $b columns plotted together? (a comparison of the two?) thanks. DISCLAIMER: This e-mail message and any attachments are inte...{{dropped}}
Hi Zack, you mean something like: matplot(x$a, as.matrix(cbind(x$b, y$b)), lty=1:2, type="l") legend(1, 2.5, c("b.x", "b.y"), lty=1:2, col=1:2) I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Apoian, Zack" <Zack.Apoian at sac.com> To: "'R-help at lists.R-project.org'" <R-help at stat.math.ethz.ch> Sent: Friday, November 26, 2004 3:34 PM Subject: [R] plotting multiple series in one plot> say we have: > >> x<-data.frame(a=c(1,2,3,4,5),b=c(1,1,1.5,2,2)) >> y<-data.frame(a=c(1,2,3,4,5),b=c(1,2,2,3,3)) > > How would I plot this so that, with the shared $a as the x-axis > values, I > have both $b columns plotted together? (a comparison of the two?) > > thanks. > > > DISCLAIMER: This e-mail message and any attachments are > inte...{{dropped}} > > ______________________________________________ > R-help at 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 >
Apoian, Zack <Zack.Apoian <at> sac.com> writes: : : say we have: : : > x<-data.frame(a=c(1,2,3,4,5),b=c(1,1,1.5,2,2)) : > y<-data.frame(a=c(1,2,3,4,5),b=c(1,2,2,3,3)) : : How would I plot this so that, with the shared $a as the x-axis values, I : have both $b columns plotted together? (a comparison of the two?) I have converted your data to ts class since you have described them as time series and they appear to be regularly spaced. I have modified your example slightly so that time scales are not the same just to show that the code still works in that case. The code does rely on the series being regularly spaced (if they are irregular see plot.zoo in the zoo package). x<-data.frame(a=c(2,3,4,5,6),b=c(1,1,1.5,2,2)) y<-data.frame(a=c(1,2,3,4),b=c(1,2,2,3)) xts <- ts(x$b,start=x$a[1]) yts <- ts(y$b,start=y$a[1]) ts.plot(xts,yts,col=c("red","blue"))