[R] mtext uses the typographical descender to align text

Uwe Ligges ligges at statistik.uni-dortmund.de
Mon Aug 14 17:59:53 CEST 2006



Andreas Svensson wrote:
> Hi
> 
> The reason I use expression is to get italics. Perhaps this is possible 
> some other way?


1. Yes, see ?mtext:

plot(1:10)
mtext("Hello World", 3, font=3)


2. expression() has to use bounding boxes for several reasons, in 
particular fractions spring to mind at once. Solutions as Peter suggested:
   plot(1:10)
   mtext(expression("Hello World" * phantom("g")), 3)

Uwe Ligges



> /A
> 
> Peter Dalgaard wrote:
> 
>> Andreas Svensson <andreas.svensson at bio.ntnu.no> writes:
>>
>>  
>>
>>> <>
>>>
>>> Hello
>>>
>>> One sometimes (quite often really ) marvel at the choice of defaults in 
>>> R's graphic engine.
>>> For some obscure reason, mtext uses the typographical  descender (bottom 
>>> of letters) to align text. That is: "gG" will end up slightly higher 
>>> that "GG". Depending on the font, "Q" might end up higher than "O".
>>>
>>> (for explanation of baseline & descender see: 
>>> http://www.paratype.com/help/term/terms.asp?code=88)
>>>    
>>>
>> <snip>
>>  
>>
>>> mtext(expression(italic("Normal 1"))   ,1 ,  line=1, at=1)
>>>    
>>>
>> <snap>
>>  
>>
>>> As the word "Higher" includes a descending letter (g), this factor name 
>>> ends up higher.
>>> I must say I have never encountered a software that uses the 
>>> typographical descender instead of the baseline to align text .
>>>
>>> Does anyone know how to make R use the baseline instead? Perhaps using  
>>> adj or padj? Or do I have to do something silly as adding
>>> "g", col=white
>>> to each mtext-line to trick R into aligning the names.
>>>    
>>>
>> Notice that it only happens when plotting math expressions. Using 
>>
>> mtext("Normal 1"   ,1 ,  line=1, at=1,font=3)
>> mtext("Higher 1 "  ,1 ,  line=1, at=2, font=3)
>> etc.
>>
>> does not exhibit the same effect. 
>>
>> I suppose the idea is that math expressions can grow arbitrarily tall
>> or deep, and that the design decision (wise or not) has been to align
>> on the bounding box of the whole enchilada. For a workaround, if you
>> do need to do it with expressions, notice the phantom() construction.
>>
>>  
>>
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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