[R] Two y-axis in plots
otoomet at econ.dk
Fri Apr 4 16:06:12 CEST 2003
| From: "Allan McRae" <s0238397 at sms.ed.ac.uk>
| Date: Thu, 3 Apr 2003 11:53:32 +0100
| 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().
> 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.
More information about the R-help