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:

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

which produces this: