# [R] Plotting quiver vector tensor arrows 2d field data

From: David Forrest <drf5n_at_maplepark.com>
Date: Wed 15 Jun 2005 - 04:55:24 EST

Hi All,

I'd like to plot something like
http://www.nawcwpns.navy.mil/~weather/mugu/mesodata/analysis.html

Looking through the galleries at

``` http://addictedtor.free.fr/graphiques/allgraph.php
http://r-spatial.sourceforge.net/gallery/
http://fawn.unibw-hamburg.de/cgi-bin/Rwiki.pl?GraphGallery

```

demo(graphics)

I did not find a function to plot a 2d field on a matrix. I did find mention of a quiver function in the archives. Is this the best solution or are there other tools I missed?

quiver<- function(u,v,scale=1,length=0.05)
# first stab at matlab's quiver in R
# from
http://tolstoy.newcastle.edu.au/R/help/01c/2711.html
# Robin Hankin Tue 20 Nov 2001 - 13:10:28 EST
{
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=length*min(par.uin()))   }

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/(u - u), p/(u - u)) }

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

I added these functions as an example to the Wiki: http://fawn.unibw-hamburg.de/cgi-bin/Rwiki.pl?GraphGallery http://fawn.unibw-hamburg.de/cgi-bin/Rwiki.pl?QuiverPlot

Dave

```--
Dr. David Forrest
drf@vims.edu                                    (804)684-7900w
drf5n@maplepark.com                             (804)642-0662h
http://maplepark.com/~drf5n/

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help