[R] Finding the "height of a line of text" for axis

Paul Murrell p.murrell at auckland.ac.nz
Thu Mar 31 02:17:19 CEST 2005


Hi


Steven J. Murdoch wrote:
> Thanks for your reply.
> 
> On Wed, Mar 30, 2005 at 08:03:10AM -0600, Marc Schwartz wrote:
> 
>>or even something like this:
>>
>> plot(1:5, axes = FALSE)
>> axis(1, col.axis = "white", col = "red", tcl = 1)
>> axis(1, col.axis = "white", col = "white", tcl = 0)
>> axis(2, col.axis = "white", col = "red", tcl = 1)
>> axis(2, col.axis = "white", col = "white", tcl = 0)
> 
> 
> This is the effect I am trying to achieve. I did try the route of
> overdrawing in white, but decided against it. The reason I haven't
> used that, is that firstly I wasn't sure if there would be some
> rounding error in a printer which would cause the background to
> appear. Secondly, the end of the ticks look weird due to the different
> line end types:
>  http://www.cl.cam.ac.uk/users/sjm217/volatile/r-lineend.png
> 
> Changing to square caps might help, but I was hoping there would be a
> nice solution that would let me keep round caps. Any suggestions?


The function GConvertYUnits() (and the functions it calls) are in the 
file graphics.c (same directory as plot.c), but I'd book a week off 
before trying to trace the calculations performed therein.

A more accurate calculation than ...
   l<-par("cxy")[2]*par("tcl")
... is ...
   l<-par("cin")[2]/par("pin")[1]*diff(par("usr")[1:2])*par("tcl")
... but that still needs par("cex") and a par("mex") multipliers to be 
(possibly) fully par() compliant.  This general 
replicate-par()-in-R-code route is likely to be a recipe for unhappiness.

Some sort of overplotting trick is probably a better choice if you can 
cope with the compromise.  The following variation on Marc's suggestion 
might provide a slight improvement:

  plot(1:5, axes = FALSE)
  axis(1, col.axis = "white", col = "red", tcl = 1)
  axis(2, col.axis = "white", col = "red", tcl = 1)
  box(col="white")

Something like box(col="white", lwd=1.1) could be used to allay fears of 
axes peeking through from behind.

Paul
-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/




More information about the R-help mailing list