[R] centering text across panels of an annotated lattice figure

John G. Bullock john.bullock at yale.edu
Sat Aug 31 07:05:11 CEST 2013

>> I have a multi-panel lattice figure. It has an even number of
>> equal-width columns. I would like to center text across the columns.
>> The xlab argument often handles this job nicely. But I want a more
>> flexible solution. (I have many strings and want to position them at
>> different heights, but always centered across the columns.)
>> grid.text("Label", x = unit(.5, "npc")) will work when the figure has
>> no annotations outside the panel. But when it does -- for example,
>> when I use the scales argument to create row labels -- using
>> grid.text() in this way doesn't center the text. 
> Paul Murrell wrote, On 8/26/2013 3:07 PM:
> I think if you downViewport("plot_01.figure.vp") you get what you want, for example, take a look at ...
> downViewport("plot_01.figure.vp")
> grid.rect(gp=gpar(col="red"))

Paul Murrell's downViewport()-based solution works beautifully.  Thanks, Paul.


More information about the R-help mailing list