Monday, 12 March 2012

Interactive function for distances in plots

The following R function returns the distance between two points located on a plot. The distance returned is in the same units as that of the plot.
interDist <- function(x){
    aa <- locator(2)
    dx <- aa$x[2] - aa$x[1]
    dy <- aa$y[2] - aa$y[1]
    sqrt(sum(c(dx^2, dy^2)))
}

No comments: