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

From: Steven J. Murdoch <r+Steven.Murdoch_at_cl.cam.ac.uk>
Date: Wed 30 Mar 2005 - 20:06:17 EST


I would like to draw only the ticks of an axis, but not the axis itself. I don't think this can be done using axis(), so I am trying to write a cut-down version in R, which only draws ticks.

The point at which I am stuck is that the length of a tick is set by par("tcl") as a fraction of the "height of a line of text". So I would like to draw a line whose length is also this length. However I cannot find out how to convert the into units I can pass into lines(). I thought par("cxy"), but it is too large, as is shown in the code below. Here the red tick marks are longer than the black ones created by axis. I have found the relevant function in plot.c:  "GConvertYUnits(Rf_gpptr(dd)->tcl, LINES, NFC, dd);" but can't find the corresponding R function.

Can anyone suggest how to find this out, or solve the problem in a different way?

# Inward pointing ticks

par("tcl"=1)

drawticks <- function(at) {
 # Start of the ticks
 base<-par("usr")[1]
 # Length of the ticks
 l<-par("cxy")[2]*par("tcl")
 for (i in at) {
  lines(c(base,base+l),rep(i,2),col="red")  }

}

# Test plot

plot(c(1,2,3), axes=FALSE)
# Draw ticks in red

drawticks(axTicks(2))
# Overprint with normal axis

axis(2, axTicks(2))

Thanks in advance,
Steven Murdoch.

-- 
w: http://www.cl.cam.ac.uk/users/sjm217/

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Wed Mar 30 20:22:04 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:57 EST