Chenming Zhang
Chenming Zhang

Reputation: 2566

relative position of mtext in R

when I write text in the graph plotted by R, i use mtext command. for example, to write a index (e.g. (a),(b) ) on the top left of a graph (inside), I can do

mtext("(c)",side=3,line=-1.5,at=0.05,cex=1.2)

However, the parameter at is the coordinates of x-axis. this is a bit annoying when the value range on x-axis is different (one has to change the at value for each graph). can someone give a suggestion to write text as relative values?

Thanks in advance!

Upvotes: 7

Views: 23451

Answers (1)

IRTFM
IRTFM

Reputation: 263481

Your choice of the 'line' parameter places it inside the plot area but that may be intentional I suppose:

 mtext("(c)",side=3,line=-1.5, 
             at=par("usr")[1]+0.05*diff(par("usr")[1:2]),
             cex=1.2)

That places it about one-twentieth of the way across the "x-axis".

Upvotes: 7

Related Questions