[R] Is there an R-version of rayplot

richard.kittler@amd.com richard.kittler at amd.com
Wed Jun 9 17:14:48 CEST 2004


Thanks for this example.  I have since found the 'arrows' function which is not as comprehensive as rayplot but seems to work well for basic vector field plots, e.g. 

 y <- rep(1:5,rep(5,5))  
 x <- rep(1:5,5)         

 x1 <- x-sqrt(x*x + y*y)/25
 y1 <- y-2*x/125

 plot(x,y,,main='Sample Vector Plot',type='n')
 arrows(x,y,x1,y1,length=0.1) 


--Rich

Richard Kittler 
AMD TDG
408-749-4099

-----Original Message-----
From: joerg van den hoff [mailto:j.van_den_hoff at fz-rossendorf.de] 
Sent: Wednesday, June 09, 2004 4:10 AM
Cc: Kittler, Richard; r-help at stat.math.ethz.ch
Subject: Re: [R] Is there an R-version of rayplot


maybe this q&d try helps?


#=================cut herer=============

vectorplot <- function (field) {

   #input is a (N x 4 array) of N vectors:
   #   field[,1:2] - x/y position  of vectors
   #   field[,3:4] - x/y componnent of vectors
   # plotted are the 2-D vectors attached to  the specified positions

   if (is.null(dim(field))||dim(field)[2] != 4) stop("N x 4 array expected")

   loc <- field[,1:2]
   val <- field[,3:4]

   alpha <- rbind(loc[,1],loc[,1]+val[,1])
   omega <- rbind(loc[,2],loc[,2]+val[,2])

   matplot(alpha,omega,type='l',lty=1,col='black') #the vector lines
   points(loc) #the start points
   points(loc+val,pch=20) #the end points
}

#example:

loc=matrix(rnorm(100),50,2)
field <- cbind(loc,loc)
vectorplot(field)

#=================cut herer=============

there are no nice arrow heads, of course, but one could construct some... for now, vectors start with open circles and end with filled circles.

joerg




More information about the R-help mailing list