[R] Is there an R-version of rayplot

joerg van den hoff j.van_den_hoff at fz-rossendorf.de
Wed Jun 9 13:09:35 CEST 2004

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


field <- cbind(loc,loc)

#=================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.


More information about the R-help mailing list