Hi listers, A few days ago I posted a question about the use of the stars function on selected lines of a frame. Thanks to two helpers, a closer look at the scale argument allowed to partially solve the problem. Yet I still have a problem with stars. Allow me to explain what I intend to do (sorry for my poor English and the long post): I want to graph an activity index of a fish during the day cycle with a star or radar type graph. I know that the R stars function was not written for that purpose. But I couldn't find another way to try to do it. I would appreciate if you could point me to a more appropriate function. I looked at the archives and only found the link below, which pointed me to the stars function: http://maths.newcastle.edu.au/~rking/R/help/01c/2464.html My data frame (2 cols, 55 rows) has the activity index (range 0:1) in the first column. In the second column is the cumulated time (in minutes - range 0:1440) between successive measures of activity. I would like the radius length be the activity index and the angle between two successive plots proportional to elapsed time. In addition time or a character label, is to be written on the graph. I tried with no success to graph it using both the data frame and its "transposed" (2 rows, 55 cols). As in the actual file there are 55 measures of activity at different hours of the day (not regularly spaced). You can simulate data with something like : df <- data.frame(activ=runif(55),cumtime=round(seq(1,1440,l=55))) df$cumtime[1]=0 df looks like my actual data except that the actual data are not regularly spaced in time. But this is not important for the graph. Maybe stars() is totally inadequate for the purpose. If no other solution is available in R, I will try to write down my own and post it. But it may take me a while as I am a newbie in R. Any hint will be appreciated. Regards, Tito -- L. Tito de Morais UR RAP IRD de Dakar BP 1386 Dakar S?n?gal T?l.: + 221 849 33 31 Fax: +221 832 16 75 Courriel: tito at ird.sn
Jim Lemon replied directly to me with a helpful function that needs to be adapted. Yet it almost does exactly what I want. I'm posting it so that it appears in the thread as it could be useful to others. Thank you Jim Tito Le jeu 14/08/2003 ? 15:28, Jim Lemon a ?crit :> If I understand this, it is fairly easy to write a function to do this > plot. Here is a very basic example. You will probably want to customize > this to suit your needs, and the plotting of text labels is _very_ basic. > Hope it helps. > > Jim > > # this utility just rescales data to a new range > rescale<-function(x,newrange) { > if(nargs() > 1 && is.numeric(x) && is.numeric(newrange)) { > # if newrange has max first, reverse it > if(newrange[1] > newrange[2]) { > newmin<-newrange[2] > newrange[2]<-newrange[1] > newrange[1]<-newmin > } > xrange<-range(x) > if(xrange[1] == xrange[2]) stop("can't rescale a constant vector!") > mfac<-(newrange[2]-newrange[1])/(xrange[2]-xrange[1]) > invisible(newrange[1]+(x-xrange[1])*mfac) > } > else { > cat("Usage: rescale(x,newrange)\n") > cat("\twhere x is a numeric object and newrange is the min and max of > the new range\n") > } > } > > star.plot<-function(lengths,rad.pos,labels) { > maxlength<-max(lengths)+0.1*!missing(labels) > plot(c(-maxlength,maxlength),c(-maxlength,maxlength),type="n",axes=FALSE, > xlab="",ylab="") > npos<-length(rad.pos) > # add one space to prevent overlapping > newrange<-c(0,2*pi*npos/(npos+1)) > # rescale to a range of 0 to almost 2pi > rad.pos<-rescale(rad.pos,newrange) > # get the vector of x positions > xpos<-cos(rad.pos)*lengths > # get the vector of y positions > ypos<-sin(rad.pos)*lengths > segments(0,0,xpos,ypos) > if(!missing(labels)) { > xpos<-xpos*1.1 > ypos<-ypos*1.1 > text(xpos,ypos,labels) > } > }-- L. Tito de Morais UR RAP IRD de Dakar BP 1386 Dakar S?n?gal T?l.: + 221 849 33 31 Fax: +221 832 16 75 Courriel: tito at ird.sn