Dual coordinate plots in R

Written by  on January 11, 2010

The default plot functions in R don’t seem to facilitate plotting two dependent variables using different scales on the same plot, against the same independent axis. But it’s not that difficult, as I learned from: Jim Lemon’s “Kickstarting R”. But even his example isn’t simple enough for me. So, I generated this:

plot(1:11, 1:11, ylab="", col="green", axes=F)
axis(2,1:11, col="green")
plot(1:11, 5:-5, ylab="", axes=FALSE, pch=3, col="blue")
axis(4, -5:5, col="blue")

which produces this: