[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[1]/(u[2] - u[1]), p[2]/(u[4] - u[3])) }

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

Thanks for your time,
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
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Wed Jun 15 05:11:06 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:36 EST