Skip to Content

Adding multi-plot axes

In order to generate a layout with multiple plots, I have the following code with some dummy plots:

jpeg("/path/to/file",height=10000,width=5000)
plot.new()
par(mar=c(2,2,1,1), oma=c(2,4,0,0), xpd=NA)
 
for (i in 1:10) {
 
    par(mar=c(2,2,1,1),fig=c(0, 0.5, (10-i)/10, (11-i)/10), new=T)    
    matplot(rnorm(20)*sample(100,1),                                          
        col="blue",axes=F,type="l",lwd=10, xlab="",ylab="")
 
    par(mar=c(2,2,1,1),fig=c(0.5, 1, (10-i)/10, (11-i)/10), new=T)    
    matplot(rnorm(20)*sample(100,1),                                          
        col="red",axes=F,type="l",lwd=10, xlab="",ylab="")    
}
dev.off()

I want to add a vertical line/axis on the far LHS and the far RHS that span all 10 plots in a column. Since I will use this line as an axis, I need to be able to add ticks and labels.