2

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?

Community
  • 1
  • 1
ECII
  • 10,297
  • 18
  • 80
  • 121
  • 4
    `title('my title', outer = TRUE)` – rawr Jun 14 '14 at 14:50
  • Thanks! please post as an answer so that I can accept it – ECII Jun 14 '14 at 16:39
  • 1
    For future reference, you might also find `layout` useful in base graphics. [This question](http://stackoverflow.com/questions/11198767/how-to-annotate-across-or-between-plots-in-multi-plot-panels-in-r) addresses annotating across groups of plots using `layout`. – eipi10 Jun 14 '14 at 17:31

0 Answers0