I have 2 plots in a panel via par(mfrow=c(1,2))
op <- par(
oma=c(0,0,3,0),# Room for the title and legend
mfrow=c(1,2)
)
for(i in 1:2) {
plot( cumsum(rnorm(100)), type="l", lwd=3,
col=c("navy","orange")[ 1+i%%2 ],
las=1, ylab="Value",
main=paste("Random data", i) )
}
I would like to plot main title "Random plots" which will fit nicely in the middle of the 2 plots.
I tried the solution from here R - Common title and legend for combined plots using mtext and a lot of experimenting but the mtext
solution does not get the title exactly in the middle, just like the main
argument of plot()
.
Is there any alternative?