绘制ggvis面积图

时间:2018-08-29 14:32:09

标签: r ggvis

我正在尝试使用ggvis构建交互式面积图时间序列,并沿x轴显示日期,并在y轴上显示床位数。但是,我在图表的绘制方式上遇到了一些问题。

str()输出

    > str(test2)
'data.frame':   5000 obs. of  3 variables:
 $ Beds  : num  22 0 0 11 18 30 0 0 3 0 ...
 $ Date  : Date, format: "2015-09-01" "2015-09-01" "2015-09-01" ...
 $ Rating: Factor w/ 5 levels "Outstanding",..: 5 5 2 5 2 5 5 5 5 5 ...

数据样本

         Date               Rating Beds
1   2015-09-01                 Good    9
2   2015-09-01 Requires improvement   30
3   2015-09-01              Unrated    8
4   2015-09-01                 Good    4
5   2015-09-01              Unrated    3
6   2015-09-01              Unrated   63
7   2015-10-01 Requires improvement   38
8   2015-10-01              Unrated    9
9   2015-10-01              Unrated    4
10  2015-10-01                 Good    4
11  2015-10-01 Requires improvement   40
12  2015-10-01              Unrated    6
13  2015-11-01                 Good    9
14  2015-11-01          Outstanding   62
15  2015-11-01                 Good    4
16  2015-11-01              Unrated    4
17  2015-12-01           Inadequate   22
18  2015-12-01 Requires improvement   30
19  2015-12-01 Requires improvement   60
20  2016-01-01                 Good    5
21  2016-01-01 Requires improvement    9
22  2016-01-01              Unrated   40
23  2016-01-01              Unrated   30
24  2016-01-01                 Good    4
25  2016-01-01                 Good    4
26  2016-01-01                 Good   49
27  2016-01-01              Unrated    8
28  2016-01-01                 Good    6
29  2016-02-01 Requires improvement   22
30  2016-02-01                 Good   13
31  2016-02-01              Unrated   15
32  2016-02-01                 Good    4
33  2016-02-01                 Good   11
34  2016-02-01                 Good    6
35  2016-03-01                 Good    6
36  2016-03-01                 Good    6
37  2016-03-01              Unrated   40
38  2016-03-01                 Good    4
39  2016-03-01 Requires improvement    4
40  2016-03-01 Requires improvement   15
41  2016-03-01 Requires improvement    9
42  2016-04-01              Unrated    4
43  2016-04-01              Unrated    3
44  2016-04-01 Requires improvement   30
45  2016-04-01              Unrated    3
46  2016-04-01 Requires improvement   38
47  2016-04-01           Inadequate   63
48  2016-04-01              Unrated    8
49  2016-05-01                 Good    6
50  2016-05-01 Requires improvement   38
51  2016-05-01 Requires improvement   22
52  2016-05-01                 Good    3
53  2016-05-01                 Good   49
54  2016-05-01                 Good    4
55  2016-05-01                 Good   11
56  2016-05-01           Inadequate   63
57  2016-06-01                 Good    3
58  2016-06-01 Requires improvement    9
59  2016-06-01                 Good   22
60  2016-06-01 Requires improvement   38
61  2016-06-01                 Good    4
62  2016-07-01                 Good   18
63  2016-07-01                 Good   55
64  2016-07-01              Unrated    3
65  2016-07-01              Unrated   10
66  2016-07-01 Requires improvement   26
67  2016-07-01                 Good   16
68  2016-07-01              Unrated   16
69  2016-08-01              Unrated   14
70  2016-08-01              Unrated    3
71  2016-08-01                 Good   18
72  2016-08-01                 Good   78
73  2016-08-01                 Good   12
74  2016-08-01                 Good   34
75  2016-08-01 Requires improvement   26
76  2016-08-01          Outstanding   62
77  2016-08-01 Requires improvement   45
78  2016-09-01              Unrated   16
79  2016-09-01                 Good   22
80  2016-09-01 Requires improvement   15
81  2016-09-01 Requires improvement   38
82  2016-09-01 Requires improvement    9
83  2016-10-01              Unrated    4
84  2016-10-01                 Good   20
85  2016-10-01              Unrated    8
86  2016-10-01                 Good   25
87  2016-11-01                 Good   29
88  2016-11-01 Requires improvement   10
89  2016-11-01                 Good   59
90  2016-11-01                 Good    4
91  2016-11-01              Unrated    8
92  2016-11-01                 Good   34
93  2016-11-01                 Good   78
94  2016-12-01                 Good   59
95  2016-12-01              Unrated   69
96  2016-12-01 Requires improvement   38
97  2016-12-01                 Good    6
98  2016-12-01                 Good   22
99  2016-12-01 Requires improvement   22
100 2017-01-01              Unrated    8
101 2017-01-01 Requires improvement   10
102 2017-02-01                 Good   35
103 2017-02-01                 Good    8
104 2017-02-01                 Good    6
105 2017-02-01                 Good   13
106 2017-02-01                 Good    3
107 2017-02-01                 Good    4
108 2017-02-01 Requires improvement   49
109 2017-02-01                 Good   12
110 2017-02-01                 Good   14
111 2017-02-01                 Good   18
112 2017-03-01 Requires improvement   30
113 2017-03-01                 Good   20
114 2017-03-01                 Good   15
115 2017-03-01                 Good    3
116 2017-03-01                 Good    3
117 2017-03-01                 Good   63
118 2017-03-01                 Good    3
119 2017-03-01                 Good    6
120 2017-03-01                 Good   11
121 2017-04-01                 Good    8
122 2017-04-01                 Good   13
123 2017-04-01 Requires improvement   22
124 2017-04-01                 Good    6
125 2017-05-01                 Good    4
126 2017-05-01          Outstanding    9
127 2017-05-01                 Good   20
128 2017-05-01                 Good    6
129 2017-05-01                 Good    6
130 2017-05-01 Requires improvement    7
131 2017-05-01                 Good    4
132 2017-05-01                 Good   63
133 2017-06-01 Requires improvement   22
134 2017-06-01                 Good    6
135 2017-06-01                 Good   18
136 2017-06-01                 Good    5
137 2017-06-01                 Good    6
138 2017-06-01                 Good   15
139 2017-06-01          Outstanding   29
140 2017-07-01 Requires improvement   22
141 2017-07-01           Inadequate   67
142 2017-07-01                 Good   30
143 2017-07-01          Outstanding    9
144 2017-07-01                 Good   42
145 2017-07-01                 Good   78
146 2017-08-01                 Good    4
147 2017-08-01                 Good    3
148 2017-08-01                 Good   12
149 2017-08-01                 Good    4
150 2017-08-01                 Good    6
151 2017-08-01          Outstanding    9
152 2017-08-01                 Good   15
153 2017-09-01                 Good    6
154 2017-09-01                 Good   16
155 2017-09-01                 Good   50
156 2017-09-01 Requires improvement   49
157 2017-09-01                 Good   18
158 2017-10-01                 Good   78
159 2017-10-01                 Good    4
160 2017-10-01                 Good   60
161 2017-10-01                 Good    3
162 2017-11-01                 Good    4
163 2017-11-01                 Good   63
164 2017-11-01                 Good   14
165 2017-11-01                 Good    4
166 2017-12-01                 Good   17
167 2017-12-01                 Good   17
168 2017-12-01                 Good    4
169 2017-12-01                 Good   22
170 2017-12-01                 Good    4
171 2018-01-01                 Good   55
172 2018-01-01                 Good    3
173 2018-01-01          Outstanding   69
174 2018-01-01                 Good    4
175 2018-01-01                 Good   42
176 2018-02-01                 Good   25
177 2018-02-01                 Good    6
178 2018-02-01 Requires improvement   67
179 2018-02-01                 Good   12
180 2018-02-01          Outstanding   69
181 2018-02-01                 Good    4
182 2018-02-01                 Good    8
183 2018-03-01                 Good   63
184 2018-03-01                 Good   42
185 2018-03-01                 Good    4
186 2018-04-01                 Good   22
187 2018-04-01                 Good   25
188 2018-04-01 Requires improvement   67
189 2018-05-01                 Good    4
190 2018-05-01                 Good    4
191 2018-05-01                 Good   20
192 2018-05-01                 Good    3
193 2018-05-01                 Good   35
194 2018-06-01 Requires improvement   62
195 2018-06-01                 Good   22
196 2018-06-01                 Good    4
197 2018-06-01                 Good    4
198 2018-06-01          Outstanding   69
199 2018-06-01                 Good   12
200 2018-07-01                 Good    7

使用此示例数据集,我尝试使用以下代码构建面积图:

ggvis(test2, x = ~Date, y = ~Beds, fill = ~Rating)%>%
    layer_ribbons()

但是,我得到了以下情节,这远非理想的!

enter image description here

有任何想法为什么会这样?

0 个答案:

没有答案