[R] is it possible to get the coordinate of mtext()?

Jim Lemon jim at bitwrit.com.au
Mon Mar 17 23:32:28 CET 2014


On 03/18/2014 09:18 AM, Jinsong Zhao wrote:
> Hi there,
>
> I hope to rotate the Y label of axis(4) with -90 degree. I can typeset
> the Y label using text() with srt = -90. However, I cannot get the
> coordinate of the position that mtext() used.
>
> In other words, I hope to convert:
> mtext("Y label", side = 4, at = 0, line = 2)
> to
> text(x, 0, "Y label", str = -90)
>
> Now, I don't know how to get the x in the above expression. I can give
> it an arbitrary value. However, I hope it could be more precise.
>
Hi Jinsong,
If you mean the distance from the axis, mtext is placed by a multiple of 
the height of a line of text. Therefore:

strheight("O") * 2

will give you an approximate distance in user units. You can then add 
this to the user coordinate of the right ordinate of the plot:

par("usr")[2]

to get your "x" value. You will probably want to adjust this to get the 
desired visual spacing.

Jim




More information about the R-help mailing list