facet_grid: как удалить графики без данных - PullRequest
0 голосов
/ 12 марта 2019

Я пытаюсь организовать компиляцию графиков (x = Datetime, y = расстояние от тега) для каждого передатчика и группировать по горизонтали по размеру. Часть данных ниже:

       Transmitter        Datetime_AST Distance.from.tag   Size.Cat Total.length
1   A69-1601-45273 2018-03-21 12:10:01         137.53248 20 - 25 cm         20.5
2   A69-1601-45274 2018-03-21 12:30:08          43.19018 20 - 25 cm         21.2
3   A69-1601-45273 2018-03-21 12:40:01         131.27861 20 - 25 cm         20.5
4   A69-1601-45274 2018-03-21 13:00:08          43.19018 20 - 25 cm         21.2
5   A69-1601-45273 2018-03-21 13:10:01         125.75597 20 - 25 cm         20.5
6   A69-1601-45274 2018-03-21 13:30:08          43.19018 20 - 25 cm         21.2
7   A69-1601-45273 2018-03-21 13:40:01          99.62169 20 - 25 cm         20.5
8   A69-1601-45274 2018-03-21 14:00:08          43.19018 20 - 25 cm         21.2
9   A69-1601-45273 2018-03-21 14:10:01         117.77000 20 - 25 cm         20.5
10  A69-1601-45274 2018-03-21 14:30:08          43.19018 20 - 25 cm         21.2
11  A69-1601-45273 2018-03-21 14:40:01         195.07842 20 - 25 cm         20.5
12  A69-1601-45274 2018-03-21 15:00:08          43.19018 20 - 25 cm         21.2
13  A69-1601-45273 2018-03-21 15:10:01         147.18855 20 - 25 cm         20.5
14  A69-1601-45274 2018-03-21 15:30:08          43.19018 20 - 25 cm         21.2
15  A69-1601-45273 2018-03-21 15:40:01         124.95396 20 - 25 cm         20.5
16  A69-1601-45274 2018-03-21 16:00:08          64.58947 20 - 25 cm         21.2
17  A69-1601-45273 2018-03-21 16:10:01         115.42036 20 - 25 cm         20.5
18  A69-1601-45274 2018-03-21 16:30:08          78.88777 20 - 25 cm         21.2
19  A69-1601-45273 2018-03-21 16:40:01         112.87597 20 - 25 cm         20.5
20  A69-1601-45274 2018-03-21 17:00:08          84.00708 20 - 25 cm         21.2
21  A69-1601-45273 2018-03-21 17:10:01         122.33559 20 - 25 cm         20.5
22  A69-1601-45274 2018-03-21 17:30:08          88.59960 20 - 25 cm         21.2
23  A69-1601-45273 2018-03-21 17:40:01         111.38173 20 - 25 cm         20.5
24  A69-1601-45274 2018-03-21 18:00:08          40.53022 20 - 25 cm         21.2
25  A69-1601-45273 2018-03-21 18:10:01         118.84145 20 - 25 cm         20.5
26  A69-1601-45274 2018-03-21 18:30:08          33.75569 20 - 25 cm         21.2
27  A69-1601-45273 2018-03-21 18:40:01          80.73597 20 - 25 cm         20.5
28  A69-1601-45274 2018-03-21 19:00:08         107.97833 20 - 25 cm         21.2
29  A69-1601-45273 2018-03-21 19:10:01          77.99570 20 - 25 cm         20.5
30  A69-1601-45274 2018-03-21 19:30:08         134.53404 20 - 25 cm         21.2
31  A69-1601-45273 2018-03-21 19:40:01          90.75000 20 - 25 cm         20.5
32  A69-1601-45274 2018-03-21 20:00:08         118.97085 20 - 25 cm         21.2
33  A69-1601-45273 2018-03-21 20:10:01          81.64339 20 - 25 cm         20.5
34  A69-1601-45274 2018-03-21 20:30:08         146.17821 20 - 25 cm         21.2
35  A69-1601-45273 2018-03-21 20:40:01          61.01586 20 - 25 cm         20.5
36  A69-1601-45274 2018-03-21 21:00:08         110.23004 20 - 25 cm         21.2
37  A69-1601-45273 2018-03-21 21:10:01          82.08104 20 - 25 cm         20.5
38  A69-1601-45274 2018-03-21 21:30:08          92.04351 20 - 25 cm         21.2
39  A69-1601-45273 2018-03-21 21:40:01          51.83826 20 - 25 cm         20.5
40  A69-1601-45274 2018-03-21 22:00:08         124.73259 20 - 25 cm         21.2
41  A69-1601-45273 2018-03-21 22:10:01         100.23964 20 - 25 cm         20.5
42  A69-1601-45274 2018-03-21 22:30:08         119.82413 20 - 25 cm         21.2
43  A69-1601-45273 2018-03-21 22:40:01          45.46907 20 - 25 cm         20.5
44  A69-1601-45274 2018-03-21 23:00:08         145.42320 20 - 25 cm         21.2
45  A69-1601-45273 2018-03-21 23:10:01          69.84188 20 - 25 cm         20.5
46  A69-1601-45274 2018-03-21 23:30:08         107.69306 20 - 25 cm         21.2
47  A69-1601-45273 2018-03-21 23:40:01         111.75592 20 - 25 cm         20.5
48  A69-1601-45274 2018-03-22 00:00:08          88.26823 20 - 25 cm         21.2
49  A69-1601-45273 2018-03-22 00:10:01          82.12265 20 - 25 cm         20.5
50  A69-1601-45274 2018-03-22 00:30:08         142.47902 20 - 25 cm         21.2
51  A69-1601-45275 2018-03-22 00:31:18        1224.11120 20 - 25 cm         21.5
52  A69-1601-45273 2018-03-22 00:40:01         125.33831 20 - 25 cm         20.5
53  A69-1601-45274 2018-03-22 01:00:08          86.89440 20 - 25 cm         21.2
54  A69-1601-45273 2018-03-22 01:10:01         105.44222 20 - 25 cm         20.5
55  A69-1601-45274 2018-03-22 01:30:08         126.19708 20 - 25 cm         21.2
56  A69-1601-45275 2018-03-22 01:31:18        1539.15314 20 - 25 cm         21.5
57  A69-1601-45273 2018-03-22 01:40:01          74.85640 20 - 25 cm         20.5
58  A69-1601-45274 2018-03-22 02:00:08          79.53466 20 - 25 cm         21.2
59  A69-1601-45275 2018-03-22 02:01:18        1539.15314 20 - 25 cm         21.5
60  A69-1601-45273 2018-03-22 02:10:01         112.84113 20 - 25 cm         20.5
61  A69-1601-45274 2018-03-22 02:30:08         104.63081 20 - 25 cm         21.2
62  A69-1601-45273 2018-03-22 02:40:01          86.24277 20 - 25 cm         20.5
63  A69-1601-45274 2018-03-22 03:00:08         124.95279 20 - 25 cm         21.2
64  A69-1601-45275 2018-03-22 03:01:18        1539.15314 20 - 25 cm         21.5
65  A69-1601-45273 2018-03-22 03:10:01          87.59457 20 - 25 cm         20.5
66  A69-1601-45274 2018-03-22 03:30:08         148.72421 20 - 25 cm         21.2
67  A69-1601-45275 2018-03-22 03:31:18        1539.15314 20 - 25 cm         21.5
68  A69-1601-45273 2018-03-22 03:40:01          92.53810 20 - 25 cm         20.5
69  A69-1601-45274 2018-03-22 04:00:08         119.83980 20 - 25 cm         21.2
70  A69-1601-45273 2018-03-22 04:10:01          91.76488 20 - 25 cm         20.5
71  A69-1601-45274 2018-03-22 04:30:08         117.39011 20 - 25 cm         21.2
72  A69-1601-45273 2018-03-22 04:40:01          63.50230 20 - 25 cm         20.5
73  A69-1601-45274 2018-03-22 05:00:08         151.94872 20 - 25 cm         21.2
74  A69-1601-45273 2018-03-22 05:10:01          96.95526 20 - 25 cm         20.5
75  A69-1601-45274 2018-03-22 05:30:08         154.13552 20 - 25 cm         21.2
76  A69-1601-45273 2018-03-22 05:40:01          88.35907 20 - 25 cm         20.5
77  A69-1601-45274 2018-03-22 06:00:08          44.11678 20 - 25 cm         21.2
78  A69-1601-45273 2018-03-22 06:10:01          38.02539 20 - 25 cm         20.5
79  A69-1601-45274 2018-03-22 06:30:08          33.29203 20 - 25 cm         21.2
80  A69-1601-45273 2018-03-22 06:40:01         109.12778 20 - 25 cm         20.5
81  A69-1601-45274 2018-03-22 07:00:08          61.88420 20 - 25 cm         21.2
82  A69-1601-45273 2018-03-22 07:10:01          88.32860 20 - 25 cm         20.5
83  A69-1601-45274 2018-03-22 07:30:08          43.19018 20 - 25 cm         21.2
84  A69-1601-45273 2018-03-22 07:40:01         104.88306 20 - 25 cm         20.5
85  A69-1601-45274 2018-03-22 08:00:08          43.19018 20 - 25 cm         21.2
86  A69-1601-45273 2018-03-22 08:10:01          98.74104 20 - 25 cm         20.5
87  A69-1601-45274 2018-03-22 08:30:08          43.19018 20 - 25 cm         21.2
88  A69-1601-45273 2018-03-22 08:40:01         103.44607 20 - 25 cm         20.5
89  A69-1601-45274 2018-03-22 09:00:08          43.19018 20 - 25 cm         21.2
90  A69-1601-45273 2018-03-22 09:10:01         104.76105 20 - 25 cm         20.5
91  A69-1601-45274 2018-03-22 09:30:08          43.19018 20 - 25 cm         21.2
92  A69-1601-45273 2018-03-22 09:40:01         105.68749 20 - 25 cm         20.5
93  A69-1601-45274 2018-03-22 10:00:08          43.19018 20 - 25 cm         21.2
94  A69-1601-45273 2018-03-22 10:10:01         141.33367 20 - 25 cm         20.5
95  A69-1601-45273 2018-03-22 10:40:01         116.56027 20 - 25 cm         20.5
96   A69-9006-1688 2018-03-22 10:41:33         112.27865 20 - 25 cm         24.0
97  A69-1601-45274 2018-03-22 11:00:08          34.19831 20 - 25 cm         21.2
98  A69-1601-45273 2018-03-22 11:10:01         135.50493 20 - 25 cm         20.5
99  A69-1601-45274 2018-03-22 11:30:08          75.78882 20 - 25 cm         21.2
100 A69-1601-45273 2018-03-22 11:40:01         136.82268 20 - 25 cm         20.5
101 A69-1601-45277 2018-03-22 11:49:01         114.89547 20 - 25 cm         23.6
102 A69-1601-45274 2018-03-22 12:00:08          69.15678 20 - 25 cm         21.2
103 A69-1601-45273 2018-03-22 12:10:01         156.34284 20 - 25 cm         20.5
104 A69-1601-45277 2018-03-22 12:19:01         143.14798 20 - 25 cm         23.6
105 A69-1601-45274 2018-03-22 12:30:08          58.48053 20 - 25 cm         21.2
106 A69-1601-45273 2018-03-22 12:40:01         112.42141 20 - 25 cm         20.5
107 A69-1601-45277 2018-03-22 12:49:01         123.17009 20 - 25 cm         23.6
108 A69-1601-45274 2018-03-22 13:00:08          85.16533 20 - 25 cm         21.2
109 A69-1601-45276 2018-03-22 13:02:24          42.25245 20 - 25 cm         20.5
110 A69-1601-45273 2018-03-22 13:10:01         135.82761 20 - 25 cm         20.5
111 A69-1601-45279 2018-03-22 13:11:43          63.40576    > 30 cm         30.3
112 A69-1601-45277 2018-03-22 13:19:01         157.26715 20 - 25 cm         23.6
113 A69-1601-45274 2018-03-22 13:30:08          71.46676 20 - 25 cm         21.2
114 A69-1601-45273 2018-03-22 13:40:01         152.83832 20 - 25 cm         20.5
115 A69-1601-45279 2018-03-22 13:41:43          39.27934    > 30 cm         30.3
116 A69-1601-45277 2018-03-22 13:49:01         155.72721 20 - 25 cm         23.6
117 A69-1601-45274 2018-03-22 14:00:08          93.47381 20 - 25 cm         21.2
118 A69-1601-45273 2018-03-22 14:10:01         126.37827 20 - 25 cm         20.5
119 A69-1601-45279 2018-03-22 14:11:43          42.90832    > 30 cm         30.3
120 A69-1601-45277 2018-03-22 14:19:01          91.97291 20 - 25 cm         23.6
121 A69-1601-45274 2018-03-22 14:30:08          73.94558 20 - 25 cm         21.2
122 A69-1601-45273 2018-03-22 14:40:01         146.18013 20 - 25 cm         20.5
123 A69-1601-45279 2018-03-22 14:41:43          60.00172    > 30 cm         30.3
124 A69-1601-45277 2018-03-22 14:49:01         136.12671 20 - 25 cm         23.6
125 A69-1601-45274 2018-03-22 15:00:08         101.08575 20 - 25 cm         21.2
126 A69-1601-45273 2018-03-22 15:10:01         105.75043 20 - 25 cm         20.5
127 A69-1601-45279 2018-03-22 15:11:43          55.04505    > 30 cm         30.3
128 A69-1601-45277 2018-03-22 15:19:01         181.52743 20 - 25 cm         23.6
129 A69-1601-45274 2018-03-22 15:30:08          87.63934 20 - 25 cm         21.2
130 A69-1601-45273 2018-03-22 15:40:01         133.46551 20 - 25 cm         20.5
131 A69-1601-45279 2018-03-22 15:41:43          61.41266    > 30 cm         30.3
132 A69-1601-45277 2018-03-22 15:49:01         158.62396 20 - 25 cm         23.6
133 A69-1601-45282 2018-03-22 15:55:18          32.86016 25 - 30 cm         25.0
134 A69-1601-45274 2018-03-22 16:00:08          76.66617 20 - 25 cm         21.2
135 A69-1601-45294 2018-03-22 16:01:27          79.92352 25 - 30 cm         25.5
136 A69-1601-45273 2018-03-22 16:10:01         117.85346 20 - 25 cm         20.5
137 A69-1601-45279 2018-03-22 16:11:43          55.88196    > 30 cm         30.3
138 A69-1601-45277 2018-03-22 16:19:01         146.70454 20 - 25 cm         23.6
139 A69-1601-45282 2018-03-22 16:25:18          32.86016 25 - 30 cm         25.0
140 A69-1601-45281 2018-03-22 16:29:35          32.86016 20 - 25 cm         23.0
141 A69-1601-45274 2018-03-22 16:30:08          56.35318 20 - 25 cm         21.2
142 A69-1601-45294 2018-03-22 16:31:27         115.63941 25 - 30 cm         25.5
143 A69-1601-45273 2018-03-22 16:40:01         136.59357 20 - 25 cm         20.5
144 A69-1601-45279 2018-03-22 16:41:43          73.91589    > 30 cm         30.3
145 A69-1601-45277 2018-03-22 16:49:01         131.77463 20 - 25 cm         23.6
146 A69-1601-45282 2018-03-22 16:55:18          32.86016 25 - 30 cm         25.0
147 A69-1601-45281 2018-03-22 16:59:35          46.71582 20 - 25 cm         23.0
148 A69-1601-45274 2018-03-22 17:00:08          71.54949 20 - 25 cm         21.2
149 A69-1601-45294 2018-03-22 17:01:27         134.42286 25 - 30 cm         25.5
150 A69-1601-45276 2018-03-22 17:02:24          42.25245 20 - 25 cm         20.5
151 A69-1601-45273 2018-03-22 17:10:01         107.57736 20 - 25 cm         20.5
152 A69-1601-45279 2018-03-22 17:11:43          51.28178    > 30 cm         30.3
153 A69-1601-45277 2018-03-22 17:19:01         138.20854 20 - 25 cm         23.6
154 A69-1601-45282 2018-03-22 17:25:18          32.86016 25 - 30 cm         25.0
155 A69-1601-45281 2018-03-22 17:29:35          40.58664 20 - 25 cm         23.0
156 A69-1601-45274 2018-03-22 17:30:08          54.64619 20 - 25 cm         21.2
157 A69-1601-45294 2018-03-22 17:31:27         113.64761 25 - 30 cm         25.5
158 A69-1601-45273 2018-03-22 17:40:01         100.17549 20 - 25 cm         20.5
159 A69-1601-45279 2018-03-22 17:41:43          67.54748    > 30 cm         30.3
160 A69-1601-45277 2018-03-22 17:49:01         139.07866 20 - 25 cm         23.6
161 A69-1601-45282 2018-03-22 17:55:18          32.86016 25 - 30 cm         25.0
162 A69-1601-45281 2018-03-22 17:59:35          61.78476 20 - 25 cm         23.0
163 A69-1601-45274 2018-03-22 18:00:08          76.66617 20 - 25 cm         21.2
164 A69-1601-45294 2018-03-22 18:01:27         108.50025 25 - 30 cm         25.5
165 A69-1601-45273 2018-03-22 18:10:01         104.71007 20 - 25 cm         20.5
166 A69-1601-45279 2018-03-22 18:11:43          61.14790    > 30 cm         30.3
167 A69-1601-45277 2018-03-22 18:19:01         141.97186 20 - 25 cm         23.6
168 A69-1601-45281 2018-03-22 18:29:35          57.54047 20 - 25 cm         23.0
169 A69-1601-45274 2018-03-22 18:30:08          76.66617 20 - 25 cm         21.2
170 A69-1601-45294 2018-03-22 18:31:27         124.04106 25 - 30 cm         25.5
171 A69-1601-45276 2018-03-22 18:32:24          43.15792 20 - 25 cm         20.5
172 A69-1601-45273 2018-03-22 18:40:01         100.68240 20 - 25 cm         20.5
173 A69-1601-45279 2018-03-22 18:41:43          77.22818    > 30 cm         30.3
174 A69-1601-45277 2018-03-22 18:49:01         115.11360 20 - 25 cm         23.6
175 A69-1601-45282 2018-03-22 18:55:18          32.86016 25 - 30 cm         25.0
176 A69-1601-45281 2018-03-22 18:59:35          35.44270 20 - 25 cm         23.0
177 A69-1601-45274 2018-03-22 19:00:08          82.05851 20 - 25 cm         21.2
178 A69-1601-45294 2018-03-22 19:01:27         113.28534 25 - 30 cm         25.5
179 A69-1601-45276 2018-03-22 19:02:24          53.09827 20 - 25 cm         20.5
180 A69-1601-45273 2018-03-22 19:10:01          92.53810 20 - 25 cm         20.5
181 A69-1601-45279 2018-03-22 19:11:43          83.79778    > 30 cm         30.3
182 A69-1601-45277 2018-03-22 19:19:01         123.80422 20 - 25 cm         23.6
183 A69-1601-45282 2018-03-22 19:25:18          40.58664 25 - 30 cm         25.0
184 A69-1601-45281 2018-03-22 19:29:35          36.60136 20 - 25 cm         23.0
185 A69-1601-45274 2018-03-22 19:30:08          45.83982 20 - 25 cm         21.2
186 A69-1601-45294 2018-03-22 19:31:27         179.76064 25 - 30 cm         25.5
187 A69-1601-45276 2018-03-22 19:32:24          28.49928 20 - 25 cm         20.5
188 A69-1601-45273 2018-03-22 19:40:01         125.33831 20 - 25 cm         20.5
189 A69-1601-45279 2018-03-22 19:41:43         114.92289    > 30 cm         30.3
190 A69-1601-45277 2018-03-22 19:49:01         146.39758 20 - 25 cm         23.6
191 A69-1601-45282 2018-03-22 19:55:18          32.86016 25 - 30 cm         25.0
192 A69-1601-45281 2018-03-22 19:59:35          42.01883 20 - 25 cm         23.0
193 A69-1601-45274 2018-03-22 20:00:08         112.96887 20 - 25 cm         21.2
194 A69-1601-45294 2018-03-22 20:01:27         205.39459 25 - 30 cm         25.5
195 A69-1601-45276 2018-03-22 20:02:24          18.62465 20 - 25 cm         20.5
196 A69-1601-45273 2018-03-22 20:10:01          96.95526 20 - 25 cm         20.5
197 A69-1601-45279 2018-03-22 20:11:43         113.30571    > 30 cm         30.3
198 A69-1601-45277 2018-03-22 20:19:01         163.20516 20 - 25 cm         23.6
199 A69-1601-45282 2018-03-22 20:25:18          32.86016 25 - 30 cm         25.0
200 A69-1601-45281 2018-03-22 20:29:35          35.56357 20 - 25 cm         23.0

Я использовал следующий код для графика ...

p <- ggplot(sizecat.PAV, aes(x = Datetime_AST, y = Distance.from.tag)) +
  scale_x_datetime(name = "Month (2018)", date_breaks = "1 months", 
                   labels = date_format(format = "%b-%Y"))+
  theme(axis.text.x = element_text(angle = 90, size=5, hjust = 0))+
  ggtitle("Averaged Positions Over Study Period")+
  theme(plot.title = element_text(hjust = 0.5)) +
  ylab("Distance from Location Tagged (m)")+ 
  facet_wrap( ~ ID, labeller = label_parsed)

p

q <- p +
  facet_grid(Size.Cat~Transmitter,space="free", scales="free",drop=TRUE) +
  geom_point()

но он создаст четыре строки повторяющихся номеров передатчиков для каждой категории размеров. Поэтому я получаю чрезвычайно сжатые графики (см. Ниже) с пустыми графиками для каждой категории размеров, потому что мои передатчики могут принадлежать только к одной категории размеров. Как я могу удалить пустые графики, чтобы отображать только отдельные экземпляры передатчиков?

Graph

...