I would like to plot two graphs in the same plotting region with horizontal grid lines. Each side of the grid lines should give the value for one graph or the other. There should be no y-axis.
plot(1:10, axes=FALSE, ylim=c(0,10), ylab="")
par(yaxp=c(0, 10, 5))
axis(2, lwd=0, col.axis="gray")
plot(60:50, axes=FALSE, ylim=c(50,60), ylab="")
par(yaxp=c(50, 60, 5))
axis(4, lwd=0, col.axis="gray")
grid() gets its locations for gridlines from
axTicks(), which in turn uses numbers from
par("yaxp"). If you modify this parameter (rather than explicitly passing it to grid), the result will then apply to both the grid drawn and the axis. For example:
plot(1:10, axes=FALSE) axis(2) #Default 4 sections between ticks par(yaxp=c(par("yaxp")[1:2], 7)) #Lets have seven instead axis(4) grid() #Grid now matches with right rather than left
Obviously similar works for the x axis.