Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

relative position of mtext in R

Tags:

plot

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!

like image 587
Chenming Zhang Avatar asked Oct 02 '22 11:10

Chenming Zhang


1 Answers

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".

like image 108
IRTFM Avatar answered Oct 13 '22 10:10

IRTFM