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

Paul Murrell p.murrell at auckland.ac.nz
Wed Nov 10 03:32:54 CET 2010


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])
>          text(U[1]+1.05*XD,U[3]+1.15*YD,labels=YR,adj=0,font=2,cex=1.5,xpd=NA)
>
> 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
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> 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/



More information about the R-help mailing list