I would like to centre titles for pairs of plots in a 3-x-2 array. Each row of the array corresponds to a calendar year and I would like to have the year value centred between the two plots in the row, and just above their upper edges. I have attached an example in "demo.pdf" showing roughly what I want. I managed to produce the example using mtext(outer=TRUE,side=3,line=<whatever>,text=YR,font=2) I got the appropriate (negative) values for "line" by trial-and-error experimentation. That's pretty kludgy, and the result only works for the screen graphics device with which I experimented. If I switch to pdf() everything is out of whack. I produced demo.pdf by plotting to the screen graphics device and then using dev.copy(). Is there a non-kludgy way of accomplishing my objective? Thanks. cheers, Rolf Turner -------------- next part -------------- A non-text attachment was scrubbed... Name: demo.pdf Type: application/pdf Size: 13253 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20101110/60dd7b4a/attachment.pdf>
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
On 11/10/2010 11:31 AM, Rolf Turner wrote:> > I would like to centre titles for pairs of plots in a 3-x-2 > array. Each row of the array corresponds to a calendar year > and I would like to have the year value centred between the > two plots in the row, and just above their upper edges. > > I have attached an example in "demo.pdf" showing roughly > what I want. I managed to produce the example using > > mtext(outer=TRUE,side=3,line=<whatever>,text=YR,font=2) > > I got the appropriate (negative) values for "line" by trial-and-error > experimentation. That's pretty kludgy, and the result only works for > the screen graphics device with which I experimented. If I switch to pdf() > everything is out of whack. I produced demo.pdf by plotting to the screen > graphics device and then using dev.copy(). > > Is there a non-kludgy way of accomplishing my objective? >Hi Rolf, The getFigCtr function might also be helpful. It allows you to get any position within the figure region in user units. You would probably want to call: getFigCtr(pos=c(0,0.9)) to place your title after drawing the right side plot in each row if I read your example correctly. Jim