圆形图和圆形统计
Posted
技术标签:
【中文标题】圆形图和圆形统计【英文标题】:Circular plots and circular statistics 【发布时间】:2022-01-17 00:37:24 【问题描述】:我有以下数据集(年、月、物种记录的频率)。我想在 R 中生成一个圆形图并检查(统计)是否存在跨月和跨年的显着变化。
我尝试使用 ggplot 生成一个圆形图,按月和年显示我的频率,但它不起作用
有什么帮助吗?下面是我的数据集。
year month frequencies
2013 Jan 0.214285714
2014 Jan 0.073170732
2015 Jan 0.073170732
2016 Jan 0
2017 Jan 0
2018 Jan 0
2013 Feb 0
2014 Feb 0.101694915
2015 Feb 0
2016 Feb 0
2017 Feb 0
2018 Feb 0.168539326
2013 Mar 0.044117647
2014 Mar 0.666666667
2015 Mar 0
2017 Mar 0.051724138
2018 Mar 1.244680851
2014 Apr 0.406779661
2015 Apr 0
2017 Apr 0.1
2018 Apr 0.923076923
2013 May 1
2014 May 0.047619048
2015 May 0.233333333
2017 May 0.066298343
2018 May 0.512195122
2013 Jun 0.260869565
2014 Jun 0.033519553
2015 Jun 0.085714286
2016 Jun 0.025641026
2017 Jun 0.137755102
2018 Jun 0.093023256
2013 Jul 0.154639175
2014 Jul 0.0703125
2015 Jul 0.18404908
2016 Jul 0
2017 Jul 0
2018 Jul 0.048648649
2013 Aug 0.068965517
2014 Aug 0.02
2015 Aug 0.060402685
2016 Aug 0
2017 Aug 0
2018 Aug 0.052631579
2013 Sep 0.090909091
2014 Sep 0.078431373
2015 Sep 0
2016 Sep 0
2017 Sep 0
2018 Sep 0
2013 Oct 0.151898734
2014 Oct 0.035714286
2015 Oct 0.023622047
2016 Oct 0
2017 Oct 0
2018 Oct 0
2013 Nov 0.092307692
2014 Nov 0
2015 Nov 0
2016 Nov 0.094488189
2017 Nov 0
2018 Nov 0.049180328
2013 Dec 0
2013 Dec 0
2014 Dec 0
2015 Dec 0
2016 Dec 0.047244094
2017 Dec 0
2018 Dec 0
【问题讨论】:
“我用 ggplot 试过了” ...你试过什么? 检查CircStats
和 circular
包
【参考方案1】:
这是一个选项。
library(ggplot2)
ggplot(dat, aes(monthnum, frequencies)) +
geom_line(aes(group = as.factor(year), color = as.factor(year))) +
coord_polar() +
scale_x_continuous(limits = c(1, 13), breaks=0:12, labels=c(month.abb, ""))
数据
我把你的月份整数化了
dat$monthnum <- match(dat$month, month.abb)
对于非英语语言环境,使用format
可能会更好地概括。
这是我使用的实际数据:
dat <- structure(list(year = c(2013L, 2014L, 2015L, 2016L, 2017L, 2018L, 2013L, 2014L, 2015L, 2016L, 2017L, 2018L, 2013L, 2014L, 2015L, 2017L, 2018L, 2014L, 2015L, 2017L, 2018L, 2013L, 2014L, 2015L, 2017L, 2018L, 2013L, 2014L, 2015L, 2016L, 2017L, 2018L, 2013L, 2014L, 2015L, 2016L, 2017L, 2018L, 2013L, 2014L, 2015L, 2016L, 2017L, 2018L, 2013L, 2014L, 2015L, 2016L, 2017L, 2018L, 2013L, 2014L, 2015L, 2016L, 2017L, 2018L, 2013L, 2014L, 2015L, 2016L, 2017L, 2018L, 2013L, 2013L, 2014L, 2015L, 2016L, 2017L, 2018L), month = c("Jan", "Jan", "Jan", "Jan", "Jan", "Jan", "Feb", "Feb", "Feb", "Feb", "Feb", "Feb", "Mar", "Mar", "Mar", "Mar", "Mar", "Apr", "Apr", "Apr", "Apr", "May", "May", "May", "May", "May", "Jun", "Jun", "Jun", "Jun", "Jun", "Jun", "Jul", "Jul", "Jul", "Jul", "Jul", "Jul", "Aug", "Aug", "Aug", "Aug", "Aug", "Aug", "Sep", "Sep", "Sep", "Sep", "Sep", "Sep", "Oct", "Oct", "Oct", "Oct", "Oct", "Oct", "Nov", "Nov", "Nov", "Nov", "Nov", "Nov", "Dec", "Dec", "Dec", "Dec", "Dec", "Dec", "Dec"), frequencies = c(0.214285714, 0.073170732, 0.073170732, 0, 0, 0, 0, 0.101694915, 0, 0, 0, 0.168539326, 0.044117647, 0.666666667, 0, 0.051724138, 1.244680851, 0.406779661, 0, 0.1, 0.923076923, 1, 0.047619048, 0.233333333, 0.066298343, 0.512195122, 0.260869565, 0.033519553, 0.085714286, 0.025641026, 0.137755102, 0.093023256, 0.154639175, 0.0703125, 0.18404908, 0, 0, 0.048648649, 0.068965517, 0.02, 0.060402685, 0, 0, 0.052631579, 0.090909091, 0.078431373, 0, 0, 0, 0, 0.151898734, 0.035714286, 0.023622047, 0, 0, 0, 0.092307692, 0, 0, 0.094488189, 0, 0.049180328, 0, 0, 0, 0, 0.047244094, 0, 0), monthnum = c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L)), row.names = c(NA, -69L), class = "data.frame")
【讨论】:
以上是关于圆形图和圆形统计的主要内容,如果未能解决你的问题,请参考以下文章