[R] Rose diagrams in R?

Joerg Maeder joerg.maeder at ethz.ch
Fri Nov 23 13:46:52 CET 2001


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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

-- 
    Joerg Maeder             IACETH              INSTITUTE
   PhD Student                              FOR ATMOSPHERIC 
  Phone: +41 1 633 36 25                 AND CLIMATE SCIENCE
 Fax: +41 1 633 10 58                  ETH ZÜRICH Switzerland
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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