Miller, Shane CONT
2001-Nov-26 20:48 UTC
[R] how to you use plot to plot multiple time series in one final gra ph
FOLKS- (R: PLOTTING) | | | =========================== A | | | | | *************************** B | ----------------------------- DIAGRAM 1 in this contrived example there are two series A,B plotted against time. (x axis is time) problem: if the range for A and B are quite different R goes stupid and only shows either A or B but not both (depending on what plot command came last i think). how do you fix that? i played around with all sorts of things on plot including this last stab: plot.new() A <- c(...) B <- c(...) plot(a,axes=FALSE,ann=FALSE) plot(b,axes=FALSE,ann=FALSE) # using code NOT shown here I figure out the # min, maxes for the X axis and therefore # determine the right at and lab arguments # for axis axis(1,at...) axis(2,at...) # ditto for Y I can routinely get R to do a nice job with the X axis with above code BUT not Y. in the axis(2...) command the graphics line for the Y axis in the plot window goes DOWN beneath the X axis even though all Y lables are positive. R is too smart to be this crazy? what is my pilot error? i hesitate to ask (and this is NOT my burning question) but what would happen if A and B had different units. can you make R plot A against the left hand side Y axis and B against the right hand side axis with appropriately labled and ticked? shane ************************************************************************** The information transmitted herewith is sensitive information intended only for use by the individual or entity to which it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Paul Murrell
2001-Nov-26 21:36 UTC
[R] how to you use plot to plot multiple time series in one final graph
Hi> | > | > | =========================== A > | > | > | > | > | *************************** B > | > ----------------------------- > DIAGRAM 1 > > in this contrived example there are two > series A,B plotted against time. (x axis > is time) > > problem: if the range for A and B are > quite different R goes stupid and only > shows either A or B but not both (depending > on what plot command came last i think). > > how do you fix that? > > i played around with all sorts of things > on plot including this last stab: > > plot.new() > A <- c(...) > B <- c(...) > plot(a,axes=FALSE,ann=FALSE) > plot(b,axes=FALSE,ann=FALSE) > # using code NOT shown here I figure out the > # min, maxes for the X axis and therefore > # determine the right at and lab arguments > # for axis > axis(1,at...) > axis(2,at...) # ditto for Y > > I can routinely get R to do a nice job with the > X axis with above code BUT not Y. in the axis(2...) > command the graphics line for the Y axis in the > plot window goes DOWN beneath the X axis even > though all Y lables are positive. > > R is too smart to be this crazy? what is my pilot > error?It *sounds* like you need xlim and ylim. Does this silly example do the sort of thing you want ... ? Ax <- sort(runif(100, 1, 200)) Ay <- runif(100, 1, 200) Bx <- sort(runif(10, 1, 1000)) By <- runif(10, 1, 1000) plot(Ax, Ay, xlim=range(Ax, Bx), ylim=range(Ay, By), type="l") lines(Bx, By, lty="dashed")> i hesitate to ask (and this is NOT my burning > question) but what would happen if A and B had > different units. can you make R plot A against the > left hand side Y axis and B against the right > hand side axis with appropriately labled and ticked?Yes; horrible example that hopefully shows the idea ... plot(1:10) par(usr=c(par("usr")[1:2], 0, 1000)) points(seq(1000, 1, length=10), pch=16) axis(4) Hope that helps. Paul -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Mark Myatt
2001-Nov-27 09:33 UTC
[R] how to you use plot to plot multiple time series in one final gra ph
Miller, Shane CONT <shane.miller at capitalone.com> writes:>FOLKS- > >(R: PLOTTING) > >| >| >| =========================== A >| >| >| >| >| *************************** B >| >----------------------------- >DIAGRAM 1 > >in this contrived example there are two >series A,B plotted against time. (x axis >is time) > >problem: if the range for A and B are >quite different R goes stupid and only >shows either A or B but not both (depending >on what plot command came last i think). > >how do you fix that? > >i played around with all sorts of things >on plot including this last stab: > >plot.new() >A <- c(...) >B <- c(...) >plot(a,axes=FALSE,ann=FALSE) >plot(b,axes=FALSE,ann=FALSE) ># using code NOT shown here I figure out the ># min, maxes for the X axis and therefore ># determine the right at and lab arguments ># for axis >axis(1,at...) >axis(2,at...) # ditto for Y > >I can routinely get R to do a nice job with the >X axis with above code BUT not Y. in the axis(2...) >command the graphics line for the Y axis in the >plot window goes DOWN beneath the X axis even >though all Y lables are positive. > >R is too smart to be this crazy? what is my pilot >error? > >i hesitate to ask (and this is NOT my burning >question) but what would happen if A and B had >different units. can you make R plot A against the >left hand side Y axis and B against the right >hand side axis with appropriately labled and ticked? >The trick is to wrap it up in a function that examines both data series and sets the axis on the first plot to the combined range. Set ylim on the first plot call to: ylim = c(min(y1, y2), max(y1, y2)) For two series you need to use the axis() function. I have some examples of this in my tutorial at: http://www.myatt.demon.co.uk Mark -- Mark Myatt -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._