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

Steven J. Murdoch r+Steven.Murdoch at cl.cam.ac.uk
Wed Mar 30 12:06:17 CEST 2005


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/




More information about the R-help mailing list