[R] Plotting quiver vector tensor arrows 2d field data
David Forrest
drf5n at maplepark.com
Tue Jun 14 20:55:24 CEST 2005
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 at vims.edu (804)684-7900w
drf5n at maplepark.com (804)642-0662h
http://maplepark.com/~drf5n/
More information about the R-help
mailing list