[R] Rose diagrams in R?

Ben Bolker ben at zoo.ufl.edu
Fri Nov 23 15:02:31 CET 2001


  I played around a bit as well and I think you can do what you want with
appropriate parameter settings to stars():


rose <- function(x,breaks=NULL,col="blue",rscale=NULL) {
  y <- table(cut(x,breaks))  ## could also use hist(...,plot=FALSE)$counts
  stars(matrix(y,nrow=1),draw.segments=TRUE,scale=FALSE,colors=col,
        locations=c(0,0))
  if (length(rscale)==1)
    rscale <- pretty(y,rscale)
  if (!is.null(rscale)) {
    symbols(rep(0,length(rscale)),rep(0,length(rscale)),
            circles=rscale,inches=FALSE,add=TRUE)
  }
}

x <- runif(20)*360
rose(x,breaks=seq(0,360,by=10),rscale=5)

  This has the possible advantage that it builds on an existing function
...

  Ben Bolker

On Fri, 23 Nov 2001, Joerg Maeder wrote:

> Hello David,
>
> i wrote a small function (rose) for that problem. It accept datas
> between 0 and 360 and draw something
> like you want. You also can
>
> rose <- function(data,step=30,main='wind rose'){
>   deg2rad <- 180/pi
>   data <- (data+step/2)%%360# Values like 359 go to Sector 0
>   histdata <- hist(data,breaks=seq(0,360,by=step),plot=F) #use hist for
> counting
>   counts <- histdata$counts
>   maxcount <- max(counts)
>   mids <- (histdata$mids-step/2)/deg2rad
>   step <- step/deg2rad
>   plot(c(-1,1),c(-1,1),,xlab='',ylab='',
>        main=main,xaxt='n',yaxt='n',pch=' ')
>   for (i in 1:length(counts)){
>     w1 <- mids[i]-step/2
>     w2 <- mids[i]+step/2
>     lines(counts[i]/maxcount*c(0,sin(w1),sin(w2),0),
>           counts[i]/maxcount*c(0,cos(w1),cos(w2),0))#draw sector
>     text(sin(mids[i]),cos(mids[i]),counts[i])
>   }
>   names(counts) <- round(mids*deg2rad,3)
>   counts
> }
>
> #Test with 500 values between 0 and 360 (uniform distribution)
> rose(runif(500)*360,360/16)
>
> David Finlayson wrote:
> >
> > I am looking for a function (or package) to plot histograms of directional
> > data such as wind direction.  I believe these are called rose diagrams.  Is
> > there an R script for this?  If not, can it be constructed in a function
> > calling primitive graphic calls (lines, circles, boxes or polygons)?
> >
> > The stars function is not quite right.
> >
> > --
> > David Finlayson
> > Geomorphogist and GIS Specialist
> > NearPRISM - Nearshore Research Group
> > University of Washington, Seattle, WA
> > (206) 543-7229
> >
> > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> > Send "info", "help", or "[un]subscribe"
> > (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
>

-- 
318 Carr Hall                                bolker at zoo.ufl.edu
Zoology Department, University of Florida    http://www.zoo.ufl.edu/bolker
Box 118525                                   (ph)  352-392-5697
Gainesville, FL 32611-8525                   (fax) 352-392-3704

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list