[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

This code shows an example of what I mean[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
points(20,60, pch=18)

# 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
points(20,10, pch=18)

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?

Thanks in advance,
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:

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

More information about the R-help mailing list