[R] Two y-axis in plots
Thomas W Blackwell
tblackw at umich.edu
Fri Apr 4 16:39:08 CEST 2003
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
More information about the R-help
mailing list