[R] Two axes with different scales

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Dec 2 09:55:45 CET 2003


On Tue, 2 Dec 2003, Andersson, Henrik wrote:

> Hello I would like to make a graph with two variables, with different units,
> so I would like to have two y-axes, one on the left and one on the right
> with different scales. Is this possible?

Yes.  There is an example on weight loss in the MASS/scripts/ch08.R script
which should be part of your R installation.

> I have searched through all the documentation I could find on the R homepage
> without luck and I like R very much and would rather not resort to using
> something like SigmaPlot for this seemingly simple thing.

The most comprehensive documentation on R is in real books, such as MASS 
(see the R FAQ).

> E.g. plotting the concentration of  Oxygen and it's isotopic composition in
> the same graph.

Ah, so the `different units' are actually different quantities, not just 
units?  Then the same principles apply, but you will need to change the 
plotting coordinates for the plot region before adding the second variable 
and the axis on side 4.  That is covered in `An Introduction to R' (you 
can either reset par("usr") or call plot.window()).

I suspect you actually have *three* variables, and want to plot y vs x and
z vs x, and that's the scenario I have addressed here.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list