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

Greg Snow Greg.Snow at imail.org
Wed Nov 10 05:56:45 CET 2010


Also look at the grconvertX function for a different way of finding the coordinates to plot at.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Rolf Turner
> Sent: Tuesday, November 09, 2010 7:46 PM
> To: Paul Murrell
> Cc: R-help Forum
> Subject: Re: [R] Centring titles for pairs of plots --- a solution.
> 
> 
> 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])
> >>
> 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/
> 
> ______________________________________________
> 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.



More information about the R-help mailing list