[R] plot of 2 time series with very different values

Berta ibanez at bioef.org
Fri Mar 2 11:54:57 CET 2007


Hi R-Users,

I am trying to plot two time series in the same plot, but they measure 
different things and hence one
 has values around 1-9 (Use=c(7,8, 6, 2, 3)), and the other one around 
20-100 (Resitance=c(80, 100, 95, 35, 28)). I have thought of plotting both 
in the same graph but with two axes, one from 1 to 9 and the other from 20 
to 100. To do so, I needed to do a regression for corrsepondence (1 goes to 
20 and 9 goes to 100); the code to produce the graph would be:

plot(1996:2000, xlim=c(1996, 2000),ylab="Resistence", ylim=c(20,100), 
type="n", xlab="Date")
lines(1996:2000, c(80, 100, 95, 35, 28), col=1)
axis(side=4, at=c(20,30,40,50,60,70,80,90,100), labels=c(1:9))
lines(1996:2000, lsfit(c(1,9),c(20,100))$coef[1]+ 
lsfit(c(1,9),c(20,100))$coef[2]*c(7,8,6, 2, 3), col=2)
legend(1998.5, 90, legend=c("Resistence", "Use"), fill=c(1,2))

However, I suspect there are better ways to do so, and I would like to know 
one because I have to do that many times.

Thanks a lot in advance,

Berta



More information about the R-help mailing list