# [R] xinch/yinch equivalent for log axis

Steven J. Murdoch Steven.Murdoch at cl.cam.ac.uk
Mon May 2 18:53:43 CEST 2005

```I would like to draw a vertical line from a given point, in user
coordinates, to x inches before from another point, also in user
coordinates. This is easy enough to do for linear scales, using code
based on xinch/yinch, but I do not know how to do this for logarithmic
scales.

This code shows an example of what I mean[1]:

split.screen(c(2,1))
screen(1)
# Linear scale, works fine
plot(1:100, cex=0.5, pch=19)
plotheight <- diff(par("usr")[3:4])
igap = 0.5 # intended gap, in inches
gap <- igap/par("pin")[2]*plotheight # gap in user units
lines(c(20,20),c(100,60+gap))
lines(c(20,20),c(60-gap,1))
points(20,60, pch=18)

screen(2)
# Logarithmic scale, point no longer centered
plot(1:100, cex=0.5, pch=19, log="y")
plotheight <- diff(par("usr")[3:4])
igap = 10
gap <- igap/par("pin")[2]*plotheight
lines(c(20,20),c(100,10+gap))
lines(c(20,20),c(10-gap,1))
points(20,10, pch=18)
close.screen(all=TRUE)

The top graph is as I want. The diamond is centered in the gap, and
the gap is 1 inch high (2*igap).

In bottom graph, using a log scale, the diamond is no longer centered
in the gap and there is a non-linear relationship between the gap
height in inches and igap.

I understand why this is happening, and this is why the xinch and
yinch functions raise a warning, but is there a way to handle it? For
example, is there a function which will return the user coordinate of
a point, x inches above a given point p (in user coordinates), for a
logarithmic y axis?

Steven Murdoch.

[1] I actually want to use this in a larger script, where I leave a
gap in the axis where the median in. This needs to be small but
legible to the eye, so that is why I am defining it in inches.
The source code is at:
http://www.cl.cam.ac.uk/users/sjm217/projects/graphics/fancyaxis.R

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

```