0

当我尝试在 circlize (R) 中绘制 chordDiagram 时,出现持续错误。我能够用一个数据集(Data1)很好地生成绘图,但不能用另一个(Data2),它在结构上是相同的(据我所知)。两个数据集都复制如下。它们具有相同的尺寸和结构-我认为!“年”和“月”都被识别为具有相同级别数的因子,“平均值”是一个数字。两个数据集都被 R 识别为数据框。我一定遗漏了一些东西!

我得到的错误是:
“circos.initialize 中的错误(factors = factor(cate, levels = cate), xlim = cbind(rep(0, : 由于xlim是矩阵,它应该具有与长度相同的行数) 2的级别factors和列数。"

我看过这篇文章,但是那里的解决方案对我没有帮助,所以我想我一定有一个不同的问题.....

我正在使用的代码如下:

require(circlize)

数据框(“Data1”和“Data2”)在我的问题结束时被复制。

Data1 有效 - 生成的图没有错误:

head(Data1)
Data1$Year <- as.factor(Data1$Year)
str(Data1)
# 'data.frame': 156 obs. of  3 variables:
# $ Year : Factor w/ 13 levels "2003","2004",..: 1 1 1 1 1 1 1 1 1 1 ...
# $ Month: Factor w/ 12 levels "Apr","Aug","Dec",..: 5 4 8 1 9 7 6 2 12 11.
# $ mean : num  0 0 0 0 0 ...

# Plot:
chordDiagram(Data1)

Data2 不绘图并给出错误

head(Data2)  
Data2$Year <- as.factor(Data2$Year)
str(Data2)
# 'data.frame': 156 obs. of  3 variables:
# $ Year : Factor w/ 13 levels "2003","2004",..: 1 1 1 1 1 1 1 1 1 1 ...
# $ Month: Factor w/ 12 levels "Apr","Aug","Dec",..: 5 4 8 1 9 7 6 2 12 11       
# $ mean : num  0 0 0 0 0 ...

# Plot
chordDiagram(Data2)

代码的第二部分使用 Data2 产生:“circos.initialize 中的错误(factors = factor(cate, levels = cate), xlim = cbind(rep(0, : 由于xlim是矩阵,它应该具有相同数量的rows 作为级别的长度factors和列数为 2。"

任何建议将不胜感激!

谢谢

数据1:

    Year Month        mean
1   2003   Jan  0.00000000
2   2003   Feb  0.00000000
3   2003   Mar  0.00000000
4   2003   Apr  0.00000000
5   2003   May  0.00000000
6   2003   Jun 51.25480924
7   2003   Jul 52.86618015
8   2003   Aug 18.73057776
9   2003   Sep 30.78747020
10  2003   Oct 24.64436457
11  2003   Nov 65.18283156
12  2003   Dec  5.26012515
13  2004   Jan  4.54277226
14  2004   Feb  6.48744396
15  2004   Mar 18.51936027
16  2004   Apr 20.62421203
17  2004   May 10.52632961
18  2004   Jun  0.00000000
19  2004   Jul  2.07228430
20  2004   Aug  1.42555995
21  2004   Sep  0.00000000
22  2004   Oct  0.00000000
23  2004   Nov  0.00000000
24  2004   Dec  0.32547699
25  2005   Jan  1.66109048
26  2005   Feb  0.61855670
27  2005   Mar  3.44998035
28  2005   Apr  2.59668067
29  2005   May  0.36585366
30  2005   Jun  0.36258235
31  2005   Jul  6.59261048
32  2005   Aug  6.74112309
33  2005   Sep  3.26467331
34  2005   Oct  5.03515889
35  2005   Nov 12.43620184
36  2005   Dec  0.77694983
37  2006   Jan  0.00000000
38  2006   Feb  0.39627929
39  2006   Mar  0.77348066
40  2006   Apr  1.27516779
41  2006   May  0.11111111
42  2006   Jun  0.00000000
43  2006   Jul 11.54743590
44  2006   Aug 12.46652756
45  2006   Sep  8.53900709
46  2006   Oct  0.00000000
47  2006   Nov  2.87531133
48  2006   Dec  4.86021505
49  2007   Jan  0.74007156
50  2007   Feb  0.00000000
51  2007   Mar  0.60000000
52  2007   Apr  0.00000000
53  2007   May  0.53333333
54  2007   Jun  0.00000000
55  2007   Jul  4.36056332
56  2007   Aug  0.00000000
57  2007   Sep  3.72926026
58  2007   Oct  4.91828416
59  2007   Nov  7.32487797
60  2007   Dec  0.00000000
61  2008   Jan  5.88456083
62  2008   Feb  0.00000000
63  2008   Mar  1.14460094
64  2008   Apr  0.00000000
65  2008   May  0.00000000
66  2008   Jun  0.00000000
67  2008   Jul  0.00000000
68  2008   Aug  1.01011920
69  2008   Sep  2.61201413
70  2008   Oct  0.00000000
71  2008   Nov  0.00000000
72  2008   Dec  0.00000000
73  2009   Jan  5.74589612
74  2009   Feb  0.00000000
75  2009   Mar  2.42530066
76  2009   Apr  0.00000000
77  2009   May  2.28169014
78  2009   Jun  0.00000000
79  2009   Jul  3.37186343
80  2009   Aug  0.00000000
81  2009   Sep  9.67179487
82  2009   Oct  0.00000000
83  2009   Nov  4.00091324
84  2009   Dec  4.99561129
85  2010   Jan  0.00000000
86  2010   Feb  2.02962604
87  2010   Mar  0.11764706
88  2010   Apr  0.00000000
89  2010   May  1.38919826
90  2010   Jun  1.46666667
91  2010   Jul  0.47246377
92  2010   Aug  0.00000000
93  2010   Sep  0.00000000
94  2010   Oct  4.40459770
95  2010   Nov  0.00000000
96  2010   Dec  0.00000000
97  2011   Jan  0.40000000
98  2011   Feb  0.00000000
99  2011   Mar  0.00000000
100 2011   Apr  1.07972802
101 2011   May  0.00000000
102 2011   Jun  0.60277778
103 2011   Jul 10.82795699
104 2011   Aug  7.09462366
105 2011   Sep  1.24684685
106 2011   Oct  0.00000000
107 2011   Nov  3.65154853
108 2011   Dec  0.00000000
109 2012   Jan  1.28210424
110 2012   Feb  0.00000000
111 2012   Mar  1.77027890
112 2012   Apr  0.00000000
113 2012   May  2.00831169
114 2012   Jun  6.44055944
115 2012   Jul 11.02296928
116 2012   Aug  0.00000000
117 2012   Sep  9.22877123
118 2012   Oct  0.00000000
119 2012   Nov  2.37818182
120 2012   Dec  0.00000000
121 2013   Jan  2.34805195
122 2013   Feb  0.00000000
123 2013   Mar  0.00000000
124 2013   Apr  3.43796837
125 2013   May  2.79489914
126 2013   Jun  3.97525791
127 2013   Jul 17.69100716
128 2013   Aug  0.00000000
129 2013   Sep 24.65628317
130 2013   Oct  0.00000000
131 2013   Nov  6.90997527
132 2013   Dec  0.00000000
133 2014   Jan  0.00000000
134 2014   Feb  2.17611657
135 2014   Mar  0.77922078
136 2014   Apr  0.00000000
137 2014   May  2.05913758
138 2014   Jun  1.23313580
139 2014   Jul  2.17882118
140 2014   Aug  0.00000000
141 2014   Sep  1.55084316
142 2014   Oct  0.00000000
143 2014   Nov  0.77922078
144 2014   Dec  0.00000000
145 2015   Jan  0.00000000
146 2015   Feb  0.07633588
147 2015   Mar  0.00000000
148 2015   Apr  0.39958534
149 2015   May  1.95279500
150 2015   Jun  0.00000000
151 2015   Jul  6.69971250
152 2015   Aug 11.42582933
153 2015   Sep 11.28810414
154 2015   Oct  0.00000000
155 2015   Nov  3.97264445
156 2015   Dec  0.00000000

数据2:

    Year Month        mean
1   2003   Jan   0.0000000
2   2003   Feb   0.0000000
3   2003   Mar   0.0000000
4   2003   Apr   0.0000000
5   2003   May   0.0000000
6   2003   Jun   0.0000000
7   2003   Jul   0.0000000
8   2003   Aug   0.0000000
9   2003   Sep   0.0000000
10  2003   Oct   2.2222222
11  2003   Nov   3.3333333
12  2003   Dec  17.7777778
13  2004   Jan   0.0000000
14  2004   Feb   0.0000000
15  2004   Mar   0.0000000
16  2004   Apr   1.1111111
17  2004   May  23.5609103
18  2004   Jun  42.2757697
19  2004   Jul  42.5814536
20  2004   Aug  29.6251673
21  2004   Sep   8.8888889
22  2004   Oct   4.4444444
23  2004   Nov   3.3333333
24  2004   Dec   3.3333333
25  2005   Jan   0.0000000
26  2005   Feb   0.0000000
27  2005   Mar   0.0000000
28  2005   Apr   0.0000000
29  2005   May 149.3280106
30  2005   Jun   6.6666667
31  2005   Jul  64.4444444
32  2005   Aug  18.8888889
33  2005   Sep  20.0000000
34  2005   Oct   7.7777778
35  2005   Nov   5.0000000
36  2005   Dec   2.2222222
37  2006   Jan   0.0000000
38  2006   Feb   0.0000000
39  2006   Mar   0.0000000
40  2006   Apr   0.0000000
41  2006   May   2.2222222
42  2006   Jun  66.6666667
43  2006   Jul  26.6666667
44  2006   Aug  25.5555556
45  2006   Sep  11.1111111
46  2006   Oct   4.4444444
47  2006   Nov   2.2222222
48  2006   Dec  17.7777778
49  2007   Jan   0.0000000
50  2007   Feb   0.0000000
51  2007   Mar   0.0000000
52  2007   Apr   0.0000000
53  2007   May  53.3333333
54  2007   Jun  36.6666667
55  2007   Jul  26.6666667
56  2007   Aug   0.0000000
57  2007   Sep   0.0000000
58  2007   Oct   0.0000000
59  2007   Nov   0.0000000
60  2007   Dec   0.0000000
61  2008   Jan   0.0000000
62  2008   Feb   0.0000000
63  2008   Mar   0.0000000
64  2008   Apr   0.0000000
65  2008   May   0.0000000
66  2008   Jun   0.0000000
67  2008   Jul   0.0000000
68  2008   Aug   0.0000000
69  2008   Sep   0.0000000
70  2008   Oct   0.0000000
71  2008   Nov   0.0000000
72  2008   Dec   0.0000000
73  2009   Jan   0.0000000
74  2009   Feb   0.0000000
75  2009   Mar   1.1111111
76  2009   Apr   9.4444444
77  2009   May  18.3333333
78  2009   Jun  18.8888889
79  2009   Jul  17.7777778
80  2009   Aug  22.2222222
81  2009   Sep   8.3333333
82  2009   Oct  13.8888889
83  2009   Nov  15.0000000
84  2009   Dec  13.8888889
85  2010   Jan   0.0000000
86  2010   Feb   0.0000000
87  2010   Mar   0.0000000
88  2010   Apr   0.0000000
89  2010   May  11.6666667
90  2010   Jun  17.2222222
91  2010   Jul   3.3333333
92  2010   Aug   0.0000000
93  2010   Sep   0.0000000
94  2010   Oct   0.0000000
95  2010   Nov   0.0000000
96  2010   Dec   0.0000000
97  2011   Jan   0.0000000
98  2011   Feb   0.0000000
99  2011   Mar   0.0000000
100 2011   Apr   5.9259259
101 2011   May  93.3333333
102 2011   Jun  10.3703704
103 2011   Jul  19.2592593
104 2011   Aug  14.8148148
105 2011   Sep   1.4814815
106 2011   Oct   3.7037037
107 2011   Nov  14.0740741
108 2011   Dec  11.8518519
109 2012   Jan   0.0000000
110 2012   Feb   0.0000000
111 2012   Mar   0.0000000
112 2012   Apr 184.4444444
113 2012   May 274.0740741
114 2012   Jun  37.0370370
115 2012   Jul  17.7777778
116 2012   Aug   0.0000000
117 2012   Sep   7.4074074
118 2012   Oct  12.5925926
119 2012   Nov  19.2592593
120 2012   Dec  28.8888889
121 2013   Jan   0.0000000
122 2013   Feb   0.0000000
123 2013   Mar   0.7407407
124 2013   Apr   1.4814815
125 2013   May  11.8518519
126 2013   Jun  62.2222222
127 2013   Jul  20.0000000
128 2013   Aug  33.3333333
129 2013   Sep  17.0370370
130 2013   Oct   0.0000000
131 2013   Nov   0.0000000
132 2013   Dec   0.0000000
133 2014   Jan   0.0000000
134 2014   Feb   0.0000000
135 2014   Mar   0.0000000
136 2014   Apr   0.0000000
137 2014   May   0.0000000
138 2014   Jun   0.0000000
139 2014   Jul   0.0000000
140 2014   Aug   0.0000000
141 2014   Sep   0.0000000
142 2014   Oct   0.0000000
143 2014   Nov   0.0000000
144 2014   Dec   0.0000000
145 2015   Jan   0.0000000
146 2015   Feb   0.0000000
147 2015   Mar   0.0000000
148 2015   Apr   0.0000000
149 2015   May   0.0000000
150 2015   Jun   0.0000000
151 2015   Jul   0.0000000
152 2015   Aug   0.0000000
153 2015   Sep   0.0000000
154 2015   Oct   0.0000000
155 2015   Nov   0.0000000
156 2015   Dec   0.0000000
4

1 回答 1

0

我用 circlize 0.4.0(仅在 Github 上可用)尝试了两个数据集,两者都可以。我注意到Data2, Jan,Feb并且Mar所有年份都为零,这可能会导致错误(就像三个月从圆圈中删除但我忘记在xlim内部调整行)。此问题已在最新版本中修复,您可以通过devtools::install_github("jokergoo/circlize").

于 2017-05-19T08:10:09.897 回答