[R] High/low level: Plot 2 time series with different axis (left and right)

Prof Brian Ripley ripley at stats.ox.ac.uk
Sun Mar 14 18:28:55 CET 2004


On Sun, 14 Mar 2004, Jan Verbesselt wrote:

> Dear R specialists,
> 
> I have two time series in a data.frame and want to plot them in the same
> plot(), with the left axis scaled to time series 1 (-700,0) and the
> right axis scaled to time series 2 (-0.2, 0.4). 
> 
> plot(timeserie1)
> lines(timeserie2, col=c(2)) => this one should be scaled differently

Why c(2)?

> with a new axis on the right handside.
> 
> How can these be visualised such that the fit is optimal for
> visualisation of the two time series? Which commands can I use?

plot(timeserie1)
par(new=T)
plot(timeserie2, yaxt="n", type="l", col=2, ylab="")
axis(4)

provided the two series have the same timebase.

-- 
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