Hi, I am trying to plot two data sets on one plot but with using a different y-axis ranges for each - preferably with one shown on each side of the graph. Is there a function that will allow me to do this. Thanks Allan McRae [[alternate HTML version deleted]]
See the axis() function. x <- rnorm(20) y<- rnorm(20) plot(x,y) axis(4,at=-3:3,labels=(-3:3)*10) axis(3,at=-3:3,labels=letters[1:7]) You may want to also consider plot(x,y,xaxt="n",yaxt="n") to suppress the x and y axes which you can rebuild with axis() to fit your purpose. See also the help file on par() for all kinds graphicals arguments. E.g., you may have to reset your margins with the "mai" options if you need enough space to include a label on the right axis. Jerome On April 3, 2003 02:53 am, Allan McRae wrote:> Hi, > > I am trying to plot two data sets on one plot but with using a different > y-axis ranges for each - preferably with one shown on each side of the > graph. > > Is there a function that will allow me to do this. > > Thanks > > Allan McRae > [[alternate HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Hi, | From: "Allan McRae" <s0238397 at sms.ed.ac.uk> | Date: Thu, 3 Apr 2003 11:53:32 +0100 | | Hi, | | I am trying to plot two data sets on one plot but with | using a different y-axis ranges for each - preferably with one shown on each side of the graph. This is a common question, you may try to search the mail archives. There is no ready-made function in any of the common packages. There may be some more-or-less suitable function either in the mailing list or somewhere in the less common packages. Basically what you have to do is to rescale your data, plot on the same graph and draw a new axis using axis().> plot(data1) > newdata2 <- ... #rescale your data2 into the same range as data1 > lines(data2) # or points() > a3ticks <- pretty(data2) > newa3dticks <- ... # here rescale the a3 ticks in the same way > axis(3, at=newa3ticks, labels=a3ticks) # e.g. new location but old > # labels.Perhaps it helps. Ott
Allan - Nothing canned, as far as I know. For a single plot, use plot(), then points(), axis(4, ...). See the help pages for each one. Wehn plotting the second data set using points, you will need to shift and scale the vertical coordinate yourself, to the scale of the first dataset, and do the same for axis(). Here's a somewhat cooked example. data.x <- c(1:50) data.y <- exp(rnorm(50)) data.p <- rank(data.y) / 50 # percentiles plot(data.x, data.y, pch="+") temp <- range(data.y) points(data.x, temp[1] + (temp[2] - temp[1]) * data.p, pch=20) axis(side=4, at = temp[1] + (temp[2] - temp[1]) * c(0:5) / 5, labels = c(0:5) / 5) What's cooked here is that I know by construction that data.p lies in 0 to 1, therefore I don't have to do a more complicated shift and scaling to get the second data set into the vertical scale of the first. HTH - tom blackwell - u michigan medical school - ann arbor - On Thu, 3 Apr 2003, Allan McRae wrote:> I am trying to plot two data sets on one plot but with using a different y-axis ranges for each - preferably with one shown on each side of the graph. > > Is there a function that will allow me to do this. > > Thanks > > Allan McRae
Have you considered "plot" with "axes" and "points" or "lines"? "?plot" provides examples using "points" and "lines"; "?axes" should fill in the gap. Spencer Graves Allan McRae wrote:> Hi, > > I am trying to plot two data sets on one plot but with using a different y-axis ranges for each - preferably with one shown on each side of the graph. > > Is there a function that will allow me to do this. > > Thanks > > Allan McRae > [[alternate HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help