# [R] Rose diagrams in R?

Paul Murrell p.murrell at auckland.ac.nz
Sun Nov 25 20:28:24 CET 2001

```Hi

> 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'){
>   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)
>   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])
>   }
>   counts
> }
>
> #Test with 500 values between 0 and 360 (uniform distribution)
> rose(runif(500)*360,360/16)

You might want to include a par(pty="s") in there somewhere (or something
equivalent) to make sure that the plot comes out "square".

Paul

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

```