[Rd] mtext adj= wrong with several las= (PR#7188)

Uwe Ligges ligges at statistik.uni-dortmund.de
Sun Aug 22 17:31:25 CEST 2004


ligges at statistik.uni-dortmund.de wrote:

> joehl at gmx.de wrote:
> 
> 
>>Dear all, 
>>
>>Our quite basic function mtext() does wrong adjustments in some parameter
>>configurations. This gets obvious when using multi line texts: There is no
>>way to properly adjust text perpendicular to axis 2, for example.
>>
>>Best
>>
>>
>>Jens Oehlschlägel
>>
>>
>>m <- matrix(1:9, 3)
>>colnames(m) <- c("several\nlines", "several\nlines", "several\nlines")
>>
>>par(mfrow=c(2,2))
>>barplot(m, horiz=TRUE, axes=FALSE, axisnames=FALSE, main="las=0 adj=0.5 is
>>fine")
>>mtext(colnames(m), 2, at=seq(0.5+0.2, by=1+0.2, length=3), las=0, adj=0.5)
>>barplot(m, horiz=TRUE, axes=FALSE, axisnames=FALSE, main="las=0 adj=1 is
>>different")
>>mtext(colnames(m), 2, at=seq(0.5+0.2, by=1+0.2, length=3), las=0, adj=1)
>>barplot(m, horiz=TRUE, axes=FALSE, axisnames=FALSE, main="las=1 adj=0.5 is
>>NOT fine")
>>mtext(colnames(m), 2, at=seq(0.5+0.2, by=1+0.2, length=3), las=1, adj=0.5)
>>barplot(m, horiz=TRUE, axes=FALSE, axisnames=FALSE, main="at las=1, adj=1
>>works the wrong direction", sub="no way to get adj=c(1, 0.5) with las=1 (or
>>2)")
>>mtext(colnames(m), 2, at=seq(0.5+0.2, by=1+0.2, length=3), las=1, adj=1)
>>par(mfrow=c(1,1))
>>
> 
> 
> Left / right adjustemnt seems to be perfectly OK.
> The thing that matters is centering "several lines" to the specified 
> ("at=") location.
> In fact, mtext() is not centering but bottom-aligning by adding a 
> negative distance that looks OK for one line in the default font size, 
> but not in most other cases.
> 
> Hence this is the same as Paul Murrell's PR#1659 ("mtext() alignment of 
> perpendicular text"). Fixing this, and/or improving mtext()'s "adj" 
> argument to accept 2 dimensions is desirable, but might be not that 
> easy... I'll take a look during the next days, but nothing promised.
> 
> Uwe Ligges


Having looked into the code, there are three possible solution (all with
some drawbacks) I can see. Well, the current argument "adj" becomes
"xadj" in the C sources (graphics.c, GMtext), and "yadj" is set to 0. 
Hence the ugly hard coded LineBias of 0.3.


Solutions
=========
1: Hardcode "yadj" to 0.5 and remove all those 0.3 biases. Looks good 
for axes, but it might break some code --> bad.
On the other hand, GMMathText has hardcoded yadj=0.5. Is there a problem 
with some special devices? Or any other reason not to center stuff using 
"adj=0.5"?

2: Allow the typical 2-value adj, take the first as xadj, the second one
as yadj. This might break some code, because currently adj of
arbitrary length (!=0) is allowed and recycled.

3: Invent an argument "padj" for mtext() that represents adjustment
*p*erpendicular to the text direction and gets mapped to "yadj" in
GMtext. In that case the hardcoded 0.3 bias mentioned above can be
removed. The question is whether to set the default to 0.5 (will still
break code, but easily to fix by setting padj to 0).

I'd like to propose the third solution and would be happy to provide a
patch of GMText, including corresponding patches to GMMathText, as well 
as mtext(), title() and axis() (and their inderlying do_* components).

Are there any objections? Any reasons not to do it?

Uwe Ligges



> 
> 
> 
>>>version
>>
>>         _              
>>platform i386-pc-mingw32
>>arch     i386           
>>os       mingw32        
>>system   i386, mingw32  
>>status                  
>>major    1              
>>minor    9.1            
>>year     2004           
>>month    06             
>>day      21             
>>language R   
>>
>>
> 
> 
> ______________________________________________
> R-devel at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list