swh:1:snp:a4c99a50dc49f82b591f268001b320f8c3ca0041
Raw File
Tip revision: dc000f2a5f006d137f66716b086025d618bf8306 authored by John M Chambers on 14 July 2008, 00:00:00 UTC
version 1.0-5
Tip revision: dc000f2
trackArrows.R
arrowFrom <- function(u, fraction) {
      n = length(u)
      if(n < 2)
          numeric(0)
      else
          u[-1]*(1-fraction) + u[-n]*fraction
  }

trackArrows <- function(x, y,
                        fraction, head, nArrowLengths = 5, ...) {
    x0 = arrowFrom(x, fraction);  y0 = arrowFrom(y, fraction)
    x1 = x[-1];   y1 = y[-1]
    ## compute the average line length
    delta = sqrt(mean((x1-x0)^2 + (y1-y0)^2, na.rm = TRUE))
    ## and convert it to inches for arrows()
    delta = delta * (par("pin")[1]/diff(range(x, na.rm = TRUE)))
    arrows(x0, y0, x1, y1, head * delta, ...)
}
back to top