I want to draw a rose diagram of some circular data. I have been using the circular
package and within this package it allows you to draw a simple rose diagram using the function: rose.diag
. While this draws the diagram I want to be able to improve the plots but I can't find away to add to the plot or adjust it slightly. I have looked at drawing it in ggplot2
but this doesn't seem clear to me and I am struggling to find another package in R which draws rose diagrams like this.
I post a sample of data and my current code below along with my queries:
Angle
0.65454759
0.01355458
0.5052027
0.2264302
-0.350552
-0.428481
0.1231778
0.258787
0.06723504
0.06906181
2.54608572
-1.6591672
3.00437314
-0.0503291
-0.828578
-1.9616418
-0.6468774
0.01438686
0.1162713
0.9938797
0.1861583
0.1547071
0.2577813
0.5110576
0.08714113
These data are radian turning angles. Using the circular
package I make this data a vector of class circular
:
x <- circular(Angle)
Then draw a rose diagram using the following code where it plots the diagram in degrees and not radians:
rose.diag(x, pch = 16, cex = 1, axes = TRUE, shrink = 1, col=3, prop = 2,
bins=36, upper=TRUE, ticks=TRUE, units="degrees")
There are 3 things I would like to add to this plot:
There are a few ways to do this. There is a "zero" argument for rose.diag
in this package.
y <- scan() # paste in the values from the question and hit return twice
y <- circlar(y) # not necessary but prevents a warning
rose.diag(y, units = 'degrees', zero = pi/2) # units doesn't change the underlying units
Alternatively you could have set properties of the circular
object that you created.
y <- circlar(y, zero = pi/2)
rose.diag(y, units = 'degrees') # note, no 0 call here
So, now the plot is rotated... how to add stuff...
> par('usr')
[1] -1.376553 1.376553 -1.123200 1.123200
That gives me user coordinates and tells me the plot dimensions in user space. Now I can do things like add a circle.
symbols(0, 0, circle = 0.2, inches = FALSE, add = TRUE, fg = 'red')
There is a lines.circular
function but it wasn't obvious to me how to use it. I could also plot a line using segments
or arrows
commands and draw right on the plot with them. It requires a bit of euclidean geometry to convert an angle and length of the line to points. This should all get you started.
m <- mean.circle(y)
segments(0, 0, cos(m+pi/2), sin(m+pi/2), col = 'red') # note I need to add the new 0 position... there is a lines.circular function but it wasn't obvious to me how to use it.
(tip... the framing circle in rose.diag
is at a radius of 1 so giving that to the circle
argument in symbols
will draw exactly at that point)