[R] Plotmath expressions: How to vertically adjust an axis label?

David Winsemius dwinsemius at comcast.net
Sat Jul 9 16:21:25 CEST 2011


On Jul 9, 2011, at 9:07 AM, Marius Hofert wrote:

> Dear David,
>
> thanks for the hint, I completely forgot about phantom(). With that,  
> I can solve the problem:
>
> library(lattice)
> xyplot(0~0, xlim=c(0,3), scales=list(x=list(at=c(1,1.1),
>                                     labels=c(expression(hat(theta) 
> [italic(n)]),
>                                     expression(phantom(hat(theta) 
> [italic(n)])*theta*phantom(hat(theta)[italic(n)]))))))
>
> I use phantom() to put the expression with the largest height to the  
> left of the smaller label. Then I also put it on the right side of  
> the smaller label in order to center the label again. It's certainly  
> dirty, but it solves the problem :-)

Nice work, Marius. I'm sure others will find your plotmath alignment  
research useful. I also experimented it a bit more to see if the  
flanking phantoms created spacing issues and they did not.

xyplot(0~0, xlim=c(0,3), scales=list(x=list(at=c(1,1.02),
                                     labels=c(
     expression(hat(theta) 
[italic(n)]),                                  
expression(phantom(hat(theta)[italic(n)])*theta*phantom(hat(theta) 
[italic(n)])
        )                            )))      )

-- 
David

>
> Cheers,
>
> Marius
>
> On 2011-07-09, at 24:12 , David Winsemius wrote:
>
>>
>> On Jul 8, 2011, at 6:54 PM, Marius Hofert wrote:
>>
>>> Dear expeRts,
>>>
>>> How can I vertically adjust an axis tick label so that it is  
>>> nicely aligned with
>>> the other labels?
>>>
>>> library(lattice)
>>> xyplot(0~0, xlim=c(0,3), scales=list(x=list(at=c(1,1.1),  
>>> labels=c(expression(hat(theta)[italic(n)]),expression(theta)))))
>>> ## aim: move the leftmost expression up so that theta is nicely  
>>> aligned with the second
>>
>> I don't know how to make a phantom <hat>,  so see if this is any  
>> more aesthetically acceptable:
>>
>> xyplot(0~0, xlim=c(0,3), scales=list(x=list(at=c(1,1.1),    labels=c(
>>     expression(atop(phantom(), hat(theta)[italic(n)])),
>>      expression(atop(phantom(),theta))                     )
>>       )))
>>
>>> theta.
>>>
>>> Cheers,
>>>
>>> Marius
>>> ______________________________________________
>>> 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.
>>
>> David Winsemius, MD
>> West Hartford, CT
>>
>

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list