Skip to content
Prev 12822 / 29559 Next

Plotting direction vectors from an aspect map

I've done something similar for my own work (based on polygon
centroids, but the idea is the same). The following (messy) code
should do what you want using base graphics. The inputs are the
coordinates of your cell centers, the angles of your arrows, and then
a few additional parameters which control size and shape etc.

Hope it can be of some use?

Carson

point.arrows <- function (coords, angles, size = 0.08, arrow = FALSE,
                          length=0.05, point = FALSE, point.col=NULL, ...)
{
    is.xy <- (is.list(coords) && all(c("x", "y") %in% names(coords)))
    xy <- if (is.xy) {
        coords
    }
    else xy.coords(coords[,1], coords[,2])
    x <- xy$x
    y <- xy$y
    n <- length(x)

    if (point) points(x, y, col=point.col, ...)
    ppin <- par("pin")
    pusr <- par("usr")

    if (length(size) == n)
        sizes <- size/max(size)
    else
        sizes <- size[1]

    xr <- sizes * abs(pusr[2L] - pusr[1L])/ppin[1L]
    yr <- sizes * abs(pusr[4L] - pusr[3L])/ppin[2L]
    z <- numeric()
    deg <- angles
    if (arrow)
        arrows(x, y, x + xr * sin(deg), y + yr * cos(deg), length, ...)
    else
        segments(x, y, x + xr * sin(deg), y + yr * cos(deg), ...)
}

On Fri, Sep 16, 2011 at 2:17 AM, Jonathan Greenberg
<greenberg at ucdavis.edu> wrote: