5

I created a rose diagram of aspects in degrees for location data using the 'circular' package in R and the rose.diag function, with basic aspects of N, NE, E, etc., for a total of 8 bins. However, the bins do not straddle the aspects. In other words, the first bin goes from 0-45, the 2nd from 45 to 90, and so on, which is pooling the aspect data in strange ways. Is there any way to shift the bins so 0, 45, 90, etc are the center of the bins, instead of the edges?

rose.diag(Degrees$Degrees, bins=8,zero=pi/2, units = 'degrees', rotation='clock')
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
user1955888
  • 51
  • 1
  • 2
  • I don't think this is possible without hacking the source code. I seem to recall doing that at some point, but would have to excavate the code ... – Ben Bolker Jan 07 '13 at 19:43
  • @BenBolker possible without hacking the source code but with hacking the plot:) – agstudy Jan 08 '13 at 08:46

3 Answers3

5

I think Ben is right that it cannot be done easily with rose.diag, so here is a solution using ggplot2:

library(ggplot2)
Degrees <- runif(100, 0, 360)
rose <- ggplot(mapping = aes(x = Degrees)) +
  stat_bin(breaks = (0:8 - 0.5)/8 * 360) +
  scale_x_continuous(
    breaks = 0:7/8*360, 
    labels = c("N", "NE", "E", "SE", "S", "SW", "W", "NW")
    ) +
  coord_polar(start=-pi/8)
rose

enter image description here This may not be ideal because not all of the features in rose.diag have easy equivalents in ggplot2.

orizon
  • 3,159
  • 3
  • 25
  • 30
  • see my answer for aversion with `rose.diag` – agstudy Jan 08 '13 at 09:22
  • @agstudy your answer shows skillful manipulation of raw plot elements. I personally prefer the appearance of the ggplot2 rendering and I find it easier to modify. – orizon Jan 08 '13 at 13:04
  • not. I am just answering the Op question to to shift the bins. Maybe what I did is skillful, but I prefer my rendering:) – agstudy Jan 08 '13 at 14:15
  • why not just shift around your initial dataset, and then compose your rosediagram with zero = (eg) pi – andyw Sep 14 '15 at 19:45
  • When using rose.diag I could use `points(mean(Degrees))` to add the mean direction. How can I do that using ggplot2? – Simon Mar 23 '16 at 17:55
1

You can have something like this using gridBase package. We keep using rose.diag and we hack the plot, once we are in the space of the good viewport.

enter image description here

require(grid)
#grid.newpage()
##generate some data 
x <- circular(runif(50, 0, 2*pi))
bins <- 8
rotation <- 'clock'
##tcl =0(no ticks), tcl.text=-2 to write away the ticks marks
rose.diag(x, bins=bins,zero=0,  rotation='clock',
          tcl=0,tcl.text=-2,col='#80FF00FF')
library(gridBase)
## I use the plot viewport
vp <- baseViewports()$plot
pushViewport(vp)           ## here we go!
## radial transformation 
at <- (0:bins - 0.5)/bins * 2 * pi

## ticks
grid.segments( x0 =  .95*sin(at),  y0 = 0.95*cos(at),
               x1 = 1.05*sin(at),  y1 = 1.05*cos(at),
               default.units = "native")
## ticks labels
grid.text(x = 1.1*sin(at),   default.units = "native",
          y = 1.1*cos(at),   gp=gpar(col='red'),
          label = c("N", "NE", "E", "SE", "S", "SW", "W", "NW"))

For visual aspect I add some tuning , but the some code above answer already to the question.

## dashed lines from the center for visual aspect 
grid.segments( x0 =  .95*sin(at),  y0 = 0.95*cos(at),
               x1 = 0,  0,
               gp = gpar(lty="dashed"),
               default.units = "native")

## circle just to get the same color of text
grid.circle(r=1,x=0,y=0,gp=gpar(col='red',fill=NA,lwd=2), default.units = "native")
## remove the viewport
popViewport(1)
agstudy
  • 119,832
  • 17
  • 199
  • 261
0

Why not rotate your original data? N.b. below cdat is in degrees (zero = pi / 2), whilst zero is in 2*pi

rose.diag(cdat - 10, bins = 20, col="darkgrey", prop=1.3, axes=FALSE, add=TRUE, zero = pi/2-pi/20)

Copy/pasting something I am working on:

library(circular)

raw <-read.csv("C:\\Users\\Andy\\Desktop\\business\\research\\Oxford\\MichelDish\\r.csv", header=T)
raw <-na.omit(raw)


cdat <- circular(raw [, c ("kandUnknown")],type="angles",units="degrees", rotation="clock", zero=pi/2)


plot(cdat, cex=1.1, bin=720, stack=TRUE, sep=0.035, shrink=1.8, tcl.text=.2)


ticks.circular(circular(seq(0,2*pi,pi/8)), zero=pi/2, rotation='clock', tcl=0.075)



rose.diag(cdat - 10, bins = 20, col="darkgrey", prop=1.3, axes=FALSE, add=TRUE, zero = pi/2 - pi/20)

lines(density.circular(cdat, bw=40), lwd=2, lty=1)

enter image description here

n.b. the code below gives you the old figure (above left):

rose.diag(cdat, bins = 20, col="darkgrey", prop=1.3, axes=FALSE, add=TRUE)

ps for the curious, we are using such stats for eg http://www.sciencedirect.com/science/article/pii/S0950329315001068

andyw
  • 3,505
  • 2
  • 30
  • 44