我想绘制一些循环数据的玫瑰图。我一直在使用circular
包,在这个包中,它允许您使用函数rose.diag
绘制一个简单的玫瑰图。虽然这绘制了图表我希望能够改善图表,但我找不到添加到图表或稍微调整它。我已经看过在ggplot2
中绘制它但这对我来说似乎并不清楚,我正在努力寻找R中的另一个包,它绘制了像这样的玫瑰图。
我在下面发布了一个数据样本和我当前的代码以及我的查询:
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
这些数据是弧度转向角度。使用circular
包,我将此数据设为类circular
的向量:
x <- circular(Angle)
然后使用以下代码绘制玫瑰图,其中以度数而不是弧度绘制图表:
rose.diag(x, pch = 16, cex = 1, axes = TRUE, shrink = 1, col=3, prop = 2,
bins=36, upper=TRUE, ticks=TRUE, units="degrees")
我想在这个情节中添加三件事:
答案 0 :(得分:3)
有几种方法可以做到这一点。这个包中rose.diag
有一个“零”参数。
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
或者,您可以设置您创建的circular
对象的属性。
y <- circlar(y, zero = pi/2)
rose.diag(y, units = 'degrees') # note, no 0 call here
所以,现在情节被轮换......如何添加东西......
> par('usr')
[1] -1.376553 1.376553 -1.123200 1.123200
这给了我用户坐标并告诉我用户空间中的绘图尺寸。现在我可以做一些像添加圆圈的事情。
symbols(0, 0, circle = 0.2, inches = FALSE, add = TRUE, fg = 'red')
有一个lines.circular
函数,但对我来说如何使用它并不明显。我还可以使用segments
或arrows
命令绘制一条线,然后在它们的绘图上绘制。它需要一些欧几里德几何来将线的角度和长度转换为点。这一切都应该让你开始。
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.
(提示...... rose.diag
中的框架圆的半径为1,因此circle
中的symbols
参数将精确地绘制在该点上。