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

From: Marc Schwartz <MSchwartz_at_medanalytics.com>
Date: Thu 31 Mar 2005 - 00:03:10 EST

On Wed, 2005-03-30 at 11:06 +0100, Steven J. Murdoch wrote:
> 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")
> # Length of the ticks
> l<-par("cxy")*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))

Steven,

Are you trying to do something like this:

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

```

or perhaps something like this:

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

```
``` 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)

```

If you do not want the axis labels, use:

plot(1:5, axes = FALSE, ann = FALSE)

HTH, Marc Schwartz

R-help@stat.math.ethz.ch mailing list