r - R 中带有堆叠玫瑰的圆形时间图

标签 r ggplot2 rose-plot

我在 Excel 中导入了一个数据框,其中包含以下值:

> dt <- read.csv(file="teste1.csv",head=TRUE,sep=";")
> dt
   hour occur     time    tt
1     1   one 00:00:59    59
2     2   one 08:40:02 31202
3     3   one 07:09:59 25799
4     4   one 01:22:16  4936
5     5   one 01:30:28  5428
6     6   one 01:28:57  5337
7     7   one 19:05:34 68734
8     8   one 01:57:47  7067
9     9   one 00:13:17   797
10   10   one 12:14:48 44088
11   11   one 23:24:43 84283
12   12   one 13:23:14 48194
13   13   one 02:28:51  8931
14   14   one 14:21:24 51684
15   15   one 13:26:14 48374
16   16   one 00:27:24  1644
17   17   one 15:56:51 57411
18   18   one 11:07:50 40070
19   19   one 07:18:18 26298
20   20   one 07:33:13 27193
21   21   one 10:02:03 36123
22   22   one 11:30:32 41432
23   23   one 21:21:27 76887
24   24   one 00:49:18  2958
25    1   two 21:01:11 75671
26    2   two 11:00:40 39640
27    3   two 21:40:09 78009
28    4   two 01:05:37  3937
29    5   two 00:44:17  2657
30    6   two 12:43:21 45801
31    7   two 10:53:49 39229
32    8   two 08:29:09 30549
33    9   two 05:07:46 18466
34   10   two 17:32:37 63157
35   11   two 09:35:16 34516
36   12   two 03:04:19 11059
37   13   two 23:09:13 83353
38   14   two 01:15:49  4549
39   15   two 14:24:33 51873
40   16   two 01:12:53  4373
41   17   two 21:20:11 76811
42   18   two 02:25:21  8721
43   19   two 01:17:37  4657
44   20   two 15:07:50 54470
45   21   two 22:27:32 80852
46   22   two 01:41:07  6067
47   23   two 09:40:23 34823
48   24   two 05:31:17 19877

我想根据数据帧创建一个带有堆叠玫瑰的循环时间,即每个堆叠玫瑰按发生的列进行分组,并且大小由列时间定义。

小时列表示每朵玫瑰的 x 位置。

所以我尝试了这种方式,但结果与我想要的不符:

ggplot(dt, aes(x = hour, fill = occur)) + geom_histogram(breaks = seq(0, 
    24), width = 2, colour = "grey") + coord_polar(start = 0) + theme_minimal() + 
    scale_fill_brewer() + scale_x_continuous("", limits = c(0, 24), breaks = seq(0, 24), labels = seq(0, 
        24))

我做错了什么?我想要这样的http://blog.odotech.com/Portals/57087/images/French%20landfill%20wind%20rose.png

我希望我的解释是正确的。谢谢!

最佳答案

不确定,但希望有帮助:

将你的时间值转换为数字(我使用了 chron 包,但是还有很多其他方法,所以你不必调用这个库,但这只是为了让它更直接):

library(chron)
x$tt<-hours(times(x$time))*3600+minutes(times(x$time))*60+seconds(times(x$time))

并制作图表:

p<-ggplot(x, aes(x = hour, y=tt,fill = occur)) + 
geom_bar(breaks = seq(0,24), width = 2, colour="grey",stat = "identity") +
theme_minimal() + 
scale_fill_brewer()+coord_polar(start=0)+
scale_x_continuous("", limits = c(0, 24), breaks = seq(0, 24), labels = seq(0,24))

可以吗? enter image description here

这里有些情况只有 1 种颜色,但这是由于缩放问题,因为有些情况的时间接近 24 小时,而另一些情况只有几秒钟。 您可以尝试使用构面来绘制单独的图表(最好随后使用颜色:))

p+facet_grid(~occur)+ theme(axis.title.y = theme_blank(),
                       axis.text.y =  theme_blank()) 

enter image description here

如果您按小时比较数据,则圆形图很好,但如果您还想比较发生变量的差异,则认为最好以旧式条形图显示。

关于r - R 中带有堆叠玫瑰的圆形时间图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18648115/

相关文章:

r - 提取每个月的第一个星期一

r - 用线 ggplot2 连接箱线图上的数据点

r - 如何删除 ggplot2 图末尾的间隙

r - plotly 否决 ggplot 2's scale_fill_manual' s 标签

python - 如何将颜色条添加到极坐标图(玫瑰图)?

r - ggplot 风玫瑰图

r - 使用系统命令打开具有特定路径的 Windows 资源管理器

r - x 轴上的 geom_vline 垂直线与分类数据 : ggplot2

r - 从每一行获取索引并与原始 data.frame 合并

r - 为小组创建一个具有不同颜色的 180 度玫瑰图?