# [R] Centring titles for pairs of plots --- a solution.

Rolf Turner r.turner at auckland.ac.nz
Wed Nov 10 03:45:31 CET 2010

```That's cute.  I had *thought* about using layout(), but of
course didn't see the trick of specifying *9* plots and doing
each of the text()s in a new plot.  Very suave! :-)

Thanks.

cheers,

Rolf

On 10/11/2010, at 3:32 PM, Paul Murrell wrote:

> Hi
>
> Here's one approach ...
>
> # The layout's the important bit
> layout(rbind(c(7, 7),
>              c(1, 2),
>              c(8, 8),
>              c(3, 4),
>              c(9, 9),
>              c(5, 6)),
>        heights=c(1, 5, 1, 5, 1, 5))
>
> # Dummy plots
> par(mar=c(5.1, 3.1, 0, 2))
> plot(1:10, xlab="", ylab="")
> plot(10:1, xlab="", ylab="")
> plot(1:10, xlab="", ylab="")
> plot(10:1, xlab="", ylab="")
> plot(1:10, xlab="", ylab="")
> plot(10:1, xlab="", ylab="")
>
> # Year labels
> par(mar=rep(0, 4))
> plot.new()
> text(.5, .5, 2004, cex=1.5, font=2)
> plot.new()
> text(.5, .5, 2005, cex=1.5, font=2)
> plot.new()
> text(.5, .5, 2006, cex=1.5, font=2)
>
> Paul
>
> On 10/11/2010 3:13 p.m., Rolf Turner wrote:
>>
>> I have figured out a *slightly* less kludgy way of accomplishing
>> my goal.  Still a bit of a hack, but it works and seems to be
>> consistent across graphics devices.
>>
>> Essentially it's this:  After the *first* plot in each row, do:
>>
>> 	U<- par()\$usr
>>         XD<- diff(U[1:2])
>>         YD<- diff(U[3:4])
>>
>> where "YR" is the current value of the calendar year (e.g. 2004).  Note that
>> xpd=NA is necessary since the text is being placed outside the plotting region
>> and hence will not appear unless this parameter is properly set.
>>
>> Hope this is of some use to someone besides my very good self. :-)
>>
>> 	cheers,
>>
>> 		Rolf Turner
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> and provide commented, minimal, self-contained, reproducible code.
>
> --
> Dr Paul Murrell
> Department of Statistics
> The University of Auckland
> Private Bag 92019
> Auckland
> New Zealand
> 64 9 3737599 x85392
> paul at stat.auckland.ac.nz
> http://www.stat.auckland.ac.nz/~paul/

```