gpt4 book ai didi

R中的玫瑰图

转载 作者:行者123 更新时间:2023-12-04 09:15:00 28 4
gpt4 key购买 nike

我想绘制一些圆形数据的玫瑰图。我一直在用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")

我想在这个情节中添加 3 件事:
  • 更改绘图方向,使 0 位于顶部而不是右侧。
  • 在图中添加同心圆以帮助直观解释每个“垃圾箱”的大小和重量。
  • 添加一条线来标识平均角度(如果可能,使用 sd 误差线)
  • 最佳答案

    有几种方法可以做到这一点。 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 将恰好在该点绘制)

    关于R中的玫瑰图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13429148/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com