# [R] quiver plot help

Robin Hankin r.hankin at auckland.ac.nz
Tue Nov 20 03:10:28 CET 2001

```Hello everybody

I'm trying to write a simple version of matlab's "quiver".

The idea is that I have fluid with velocity defined on a grid.  I have
a matrix of x-components of velocity and a matrix of y-components and
I want to see the overall flow pattern.  (I work with 2D fluid
mechanics problems).

My first-stab function is below:

quiver  <- function(u,v,scale=1)
# first stab at matlab's quiver in R
{
xpos <- col(u)
ypos <- max(row(u))-row(u)

speed <- sqrt(u*u+v*v)
maxspeed <- max(speed)

u <- u*scale/maxspeed
v <- v*scale/maxspeed

matplot(xpos,ypos,type="p",cex=0)
arrows(xpos,ypos,xpos+u,ypos+v,length=0.05)
}

Thus, for example

u <- matrix(rnorm(100),nrow=10)
v <- matrix(rnorm(100),nrow=10)
quiver(u,v)

This works (after a fashion), but I want to do two things:

(1) scale the arrows so that the longest of them is the same length as
the distance between two adjacent points plotted by matplot

(2) scale the arrow head to (say) one tenth of the length of its
arrow.

I can't see how to do either of these because "length" argument to
arrows specifies the length of the edges of the arrow head in inches,
not in the units of the axes.  Also, any tips on how to improve the
programming style above would also be welcome.

robin

--

Robin Hankin, Lecturer,
School of Environmental and Marine Science
Private Bag 92019 Auckland
New Zealand

r.hankin at auckland.ac.nz
tel 0064-9-373-7599 x6820; FAX 0064-9-373-7042

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```