[R] Distance between axis and label adjusted automatically?

Lasse Kliemann lasse-list-r-help-2009 at mail.plastictree.net
Sat Oct 24 00:00:28 CEST 2009

Is there a way to have the distance between label and axis 
adjusted automatically? This is interesting in particular for the 
y-axis, when it is not known in beforehand how many digits the 
numbers will have. It may happen then, that numbers and label 

All examples that I found work by estimating the required 
distance manually in beforehand and then providing large enough 
margins, or positioning the label far enough away from the axis.

I have a series of plots, that should be done automatically. They 
have different magnitudes in y-direction. So there is no 
universal estimation that looks good in all cases -- of course I 
can provide a "safety margin", but it looks stupid when there is 
too much space between label and axis.

I tried to use the relative positioning mechanism of frames, 
roughly like this:

  fb <- packGrob(fg,yaxisGrob(vp="dataRegion"),side="left")
  fg <- packGrob(fg,textGrob("y axis label",rot=90),side="left")

But it appears that the true size of the axis is not respected; 
numbers on the axis and the label still may overlap.

Can anyone provide a simple example how to do this right? I would 
favor a solution using the 'grid' package.

Thank you
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20091024/0b14559f/attachment-0002.bin>

More information about the R-help mailing list