[R] Two y-axis in plots
Ott Toomet
otoomet at econ.dk
Fri Apr 4 16:06:12 CEST 2003
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
More information about the R-help
mailing list