[R] xinch/yinch equivalent for log axis

From: Steven J. Murdoch <Steven.Murdoch_at_cl.cam.ac.uk>
Date: Tue 03 May 2005 - 02:53:43 EST

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]:

# 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))
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/

R-help@stat.math.ethz.ch mailing list
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Tue May 03 03:03:31 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:32 EST