Centering multi-line strip text in lattice

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Centering multi-line strip text in lattice

Mike Lawrence
I'm having trouble centering multi-line strip text in lattice. As the
code below demonstrates bounding box of the text is centered within
the strip, but the first line isn't centered in relation to the longer
second line. The "adj" argument to par.strip.text doesn't seem to do
much. Suggestions?

a=data.frame(
        x=rep(1:10,2)
        ,y=rep(1:10,2)
        ,z=rep(c('First Line\nLonger Second Line (1)','First Line\nLonger
Second Line (2)'),each=10)
)

xyplot(
        y~x|z
        ,data=a
        ,par.strip.text = list(cex = .75, lineheight=1, lines = 2, adj=.5),
)



--
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University

Looking to arrange a meeting? Check my public calendar:
http://tinyurl.com/mikes-public-calendar

~ Certainty is folly... I think. ~

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Centering multi-line strip text in lattice

Paul Murrell
Hi


Mike Lawrence wrote:

> I'm having trouble centering multi-line strip text in lattice. As the
> code below demonstrates bounding box of the text is centered within
> the strip, but the first line isn't centered in relation to the longer
> second line. The "adj" argument to par.strip.text doesn't seem to do
> much. Suggestions?
>
> a=data.frame(
> x=rep(1:10,2)
> ,y=rep(1:10,2)
> ,z=rep(c('First Line\nLonger Second Line (1)','First Line\nLonger
> Second Line (2)'),each=10)
> )
>
> xyplot(
> y~x|z
> ,data=a
> ,par.strip.text = list(cex = .75, lineheight=1, lines = 2, adj=.5),
> )


Here's one way, by writing your own strip function that calls the
default strip function with blanked out labels then draws the labels
directly with 'grid' calls.


xyplot(
        y~x|z
        ,data=a
        ,par.strip.text = list(lines = 1.5),
        strip=function(which.panel, factor.levels, ...) {
                strip.default(which.panel=which.panel,
                              factor.levels=rep("",
                                                length(factor.levels)),
                              ...)
                pushViewport(viewport(clip="on"))
                grid.text(factor.levels[which.panel],
                          gp=gpar(cex=.75, lineheight=1))
                popViewport()
            }
)


Paul
--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
[hidden email]
http://www.stat.auckland.ac.nz/~paul/

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Centering multi-line strip text in lattice

Mike Lawrence
Perfect, thanks!

On Wed, Mar 11, 2009 at 7:41 PM, Paul Murrell <[hidden email]> wrote:

> Hi
>
>
> Mike Lawrence wrote:
>> I'm having trouble centering multi-line strip text in lattice. As the
>> code below demonstrates bounding box of the text is centered within
>> the strip, but the first line isn't centered in relation to the longer
>> second line. The "adj" argument to par.strip.text doesn't seem to do
>> much. Suggestions?
>>
>> a=data.frame(
>>       x=rep(1:10,2)
>>       ,y=rep(1:10,2)
>>       ,z=rep(c('First Line\nLonger Second Line (1)','First Line\nLonger
>> Second Line (2)'),each=10)
>> )
>>
>> xyplot(
>>       y~x|z
>>       ,data=a
>>       ,par.strip.text = list(cex = .75, lineheight=1, lines = 2, adj=.5),
>> )
>
>
> Here's one way, by writing your own strip function that calls the
> default strip function with blanked out labels then draws the labels
> directly with 'grid' calls.
>
>
> xyplot(
>        y~x|z
>        ,data=a
>        ,par.strip.text = list(lines = 1.5),
>        strip=function(which.panel, factor.levels, ...) {
>                strip.default(which.panel=which.panel,
>                              factor.levels=rep("",
>                                                length(factor.levels)),
>                              ...)
>                pushViewport(viewport(clip="on"))
>                grid.text(factor.levels[which.panel],
>                          gp=gpar(cex=.75, lineheight=1))
>                popViewport()
>            }
> )
>
>
> Paul
> --
> Dr Paul Murrell
> Department of Statistics
> The University of Auckland
> Private Bag 92019
> Auckland
> New Zealand
> 64 9 3737599 x85392
> [hidden email]
> http://www.stat.auckland.ac.nz/~paul/
>



--
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University

Looking to arrange a meeting? Check my public calendar:
http://tinyurl.com/mikes-public-calendar

~ Certainty is folly... I think. ~

______________________________________________
[hidden email] 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.