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))> 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 -- NEU: Bis zu 10 GB Speicher f?r e-mails & Dateien! 1 GB bereits bei GMX FreeMail http://www.gmx.net/de/go/mail
ligges@statistik.uni-dortmund.de
2004-Aug-20 15:34 UTC
[Rd] mtext adj= wrong with several las= (PR#7188)
joehl@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>>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 > >
Hi Uwe, Thanks for your mail. I see it different: yes, Left / right adjustemnt seems to be perfectly OK. But at axis 1 with las=1, it's not Left / right adjustement what is needed here. Here the text needs to be right adjusted, and the (one) adj= par should determine the vertical alignment. It is a bit confusing, but for mtext, the distance to the axis is done via line= and adj= moves ALONG the axis, whatever las= says. I agree that it would be more flexible and logical to also have the 2 element form of adj=c(horizontal, vertical) here, but I fear that this creates a lot of incompatibilities with existing code and with S+. Best Jens> 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.--
"Jens Oehlschlägel"
2004-Aug-26 20:48 UTC
[Rd] mtext adj= wrong with several las= (PR#7188)
> No, adj moves not always along the axis:No, not yet. But mtext logically is oriented relative to its axis. And it should behave consistently relative to its axis. Whichever solution is choosen finally, I think it is important, that the default parametrisation will handle multi-line labels such that they are centered around at= and aligned at line=, whatever side= and las= are choosen. Beeing forced to tweak with adj= / padj= depending on side= / laswould be very impractical. This "requirement" is easily fullfilled with default adj=0.5 if we have mtext's adj= always move along the axis. With a adj= / padj= solution, different defaults would be needed for the different combinations of side= and las=. How does it S+? Best Jens # Thats my problem txt <- "This are\nfour lines\nof some\nrubish" y <- barplot(x, axes=FALSE, axisnames=FALSE, horiz=TRUE) # axis doesn't align it properly axis(2, label=rep(txt, 5), at=y, las=2, adj=0) # and no mtext parameters give vertically centered and right adjusted text mtext(rep(txt, 5), side=2, line=1, at=y, las=2, adj=0) -- Supergünstige DSL-Tarife + WLAN-Router für 0,- EUR* Jetzt zu GMX wechseln und sparen http://www.gmx.net/de/go/dsl