Dear list,

I would like to plot arrows with different colors according to arrow length, and also (if
possible) with head size proportional to arrow length. The idea is to make a quiver-like plot of
matlab with wind speed data.

So far, I´ve been able to use different colors, but I need to find a more efficient way to recode
arrow length intervals into colors. On the contrary, I can't define different head sizes, because
the "length" argument in the "arrows()" function seems to control the head size of all the
arrows at once.

Any help will be greatly appreciated.



## Generate random data
     set.seed(1)
     xcoor <- matrix(runif(20), ncol=5)
     ycoor <- matrix(runif(20), ncol=5)
       u <- matrix(rnorm(20)/10, ncol=5)
       v <- matrix(rnorm(20)/10, ncol=5)

## calculate arrows length and look histogram
     arrowlen <- sqrt(u^2 + v^2)
     hist(arrowlen)

## recode arrow lengths (by interval) into colors
## sorry, I don't know how to do it without the car  package
     library(car)
     arrowL <- recode(as.vector(arrowlen),
                                         "0='grey90';
                                     0:0.05='grey50';
                                   0.05:0.1='grey';
                                   0.1:0.15='cyan';
                                   0.15:0.2='blue';
                                   0.2:0.25='red'")

    length=0.1

par.uin <- function()
  # determine scale of inches/userunits in x and y
  # from http://tolstoy.newcastle.edu.au/R/help/01c/2714.html
  # Brian Ripley Tue 20 Nov 2001 - 20:13:52 EST
 {
    u <- par("usr")
    p <- par("pin")
    c(p[1]/(u[2] - u[1]), p[2]/(u[4] - u[3]))
  }


## plot arrows
 plot(as.vector(xcoor), as.vector(ycoor), type="p", pch=".", xlim=c(-0.2, 1.3),
      ylim=c(-0.2, 1.3))
   arrows( xcoor, ycoor, xcoor + u, ycoor + v,
          length = length*as.vector(arrowlen)*min(par.uin()), col=arrowL)



 > sessionInfo()
R version 2.8.1 (2008-12-22)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods
[7] base

other attached packages:
[1] car_1.2-9  hdf5_1.6.7



--
Héctor Villalobos <hvillalo@ipn.mx>
 CICIMAR - IPN
  La Paz, Baja California Sur, MÉXICO


	[[alternative HTML version deleted]]


