如何用异常值制作强度图?

时间:2014-11-07 23:23:56

标签: r

我从移动的仪器中通过水获取了一些数据,并且每0.5秒记录一次流量数据。我需要制作一个图表,显示沿着仪器路径的流量,选择不同颜色的流量(假设为0.1) -1.5)和所有相同颜色的异常值。

如何使用R绘制图表?

这是我的一些数据:

idNr    flow    dep
21  0.135714532 3.16
22  0.131061729 3.07
23  0.13299406  3.11
24  0.145316675 3.1
25  6.31297442  3.07
26  0.331310509 3.14
27  0.445034592 3.17
28  0.637348777 3.45
29  0.87382414  4.04
30  1.302061623 5.31
31  1.80235436  6.78
32  1.63399146  8.24
33  1.675284308 9.78
34  1.686855996 11.27
35  1.775785232 12.72
36  1.455096956 14.22
37  1.530298919 15.69
38  1.431618958 17.15
39  1.446519477 18.7
40  1.532840436 20.15
41  1.595988278 21.55
42  1.478074882 23.07
43  1.545724299 24.5
44  1.475195233 26.05
45  1.542920138 27.56
46  1.437394899 29.02
47  1.644596033 30.59
48  2.303170426 31.94
49  1.77077097  33.5
50  1.530637295 34.97
51  1.439630621 36.41
52  1.469339767 37.9
53  1.330177211 39.36
54  1.478639264 40.85
55  1.465239548 42.3
56  1.536369473 43.85
57  1.484045946 45.39
58  1.561566967 46.92
59  1.487268243 48.5
60  1.509553327 50.01
61  1.436443415 51.42
62  1.520071435 52.98
63  1.455013499 54.55
64  1.472445826 56.01
65  1.499715554 57.48
66  1.514167783 58.99
67  1.493601132 60.62
68  1.531585488 62.05
69  1.625335896 63.61
70  1.478178989 65.08
71  1.531871974 66.57
72  1.472113782 68.16
73  1.4799859   69.58
74  1.458177137 71.21
75  1.591356624 72.79
76  1.542120401 74.28
77  1.694959183 75.77
78  1.720245831 77.25
79  1.519968728 78.75
80  1.390172108 80.34
81  1.520286586 81.81
82  1.592769579 83.38
83  1.632539512 84.88
84  1.481495103 86.41
85  1.529086844 87.98
86  1.536760058 89.52
87  1.52298084  91.03
88  1.731281442 92.53
89  1.639074839 94.02
90  1.562987505 95.53
91  1.543290194 97.04
92  1.578430537 98.61
93  1.702396728 100.12
94  1.657955781 101.6
95  1.557872012 103.16
96  1.613944568 104.68
97  1.631505361 106.16
98  1.435526209 107.66
99  1.711407354 109.26
100 1.57266259  110.72
101 1.514305998 112.27
102 1.56082106  113.78
103 1.828251113 115.27
104 1.748255115 116.76
105 1.854233769 118.3
106 1.803737202 119.75
107 1.67996921  121.25
108 1.751109178 122.77
109 1.76849805  124.32
110 1.758307258 125.82
111 1.740444751 127.32
112 1.644748694 128.81
113 1.620253049 130.29
114 1.75889143  131.77
115 1.760015837 133.24
116 1.683797088 134.78
117 1.713609054 136.31
118 1.26352548  137.78
119 1.81112139  139.37
120 1.888694446 140.83
121 1.774687553 142.36
122 1.739557437 143.78
123 1.64517875  145.33
124 1.699596858 146.8
125 1.628577412 148.35
126 1.769012673 149.81
127 1.594415839 151.41
128 1.493148224 152.89
129 1.581041449 154.42
130 1.538720671 155.93
131 1.589420092 157.41
132 1.64016166  158.93
133 1.575397227 160.43
134 1.63183131  162
135 1.75038462  163.44
136 1.434958447 165.01
137 1.74120127  166.5
138 1.748106592 167.98
139 1.813005453 169.46
140 1.541089106 170.98
141 1.556216895 172.56
142 1.660628956 174.08
143 1.693981673 175.61
144 1.67059241  177.09
145 1.66300418  178.66
146 1.652198157 180.17
147 1.709649777 181.65
148 1.745386082 183.15
149 1.385201724 184.62
150 1.468321001 186.15
151 1.627495534 187.58
152 1.678188454 189.03
153 1.810850273 190.55
154 1.585102162 192.01
155 1.652869637 193.48
156 1.593472296 195.03
157 1.846131262 196.53
158 1.442232687 198.03
159 1.279801142 199.57
160 1.803737202 201.06
161 1.794407014 202.61
162 1.456371696 204
163 1.815429315 205.38
164 1.518992563 206.89
165 1.647235482 208.41
166 1.47721908  209.86
167 1.698562049 211.35
168 0.835645183 211.94
169 0.971816361 211.79
170 0.215360462 212.01
171 0.576920795 212.05
172 0.504199289 212.02
173 0.352668234 212.02
174 0.503149022 211.89
175 0.180540198 212
176 0.242642996 211.91
177 0.132911363 211.98
178 0.131504237 212
179 0.131893716 211.96
180 0.132283195 211.9
181 0.132672674 212.02
182 0.919043761 212.02
183 1.705414848 211.94
184 2.491785935 211.9
185 0.187914127 211.97
186 0.137465923 211.98
187 0.490799032 211.85
188 0.695088396 211.6
189 0.283676082 211
190 0.965362936 210.07
191 0.769205485 209.16
192 1.41417407  208.1
193 1.437885765 207.08
194 1.359908615 206.02
195 1.311925665 204.77
196 1.239993728 203.57
197 1.352713698 202.38
198 1.454984487 201.12
199 1.07880741  199.89
200 1.171552813 198.65
201 1.32237999  197.41
202 1.354385018 196.15
203 1.090512744 194.97
204 1.390356612 193.71
205 1.213781005 192.33
206 1.431367612 191.08
207 1.384149391 189.81
208 1.282003839 188.57
209 1.332777243 187.45
210 1.235528323 186.19
211 1.110193788 184.9
212 1.247866678 183.7
213 1.193442015 182.56
214 1.313545026 181.36
215 1.284521151 180.08
216 1.258253835 178.91
217 1.263683914 177.68
218 1.331011134 176.49
219 1.234639947 175.26
220 1.338309201 174.07
221 1.224766564 172.91
222 1.280519417 171.66
223 1.150706617 170.44
224 1.260841259 169.25
225 1.09289038  168.05
226 1.262740102 166.84
227 1.170657422 165.68
228 1.176689196 164.49
229 1.262806038 163.31
230 1.40733017  162.17
231 1.24825008  160.93
232 1.282003839 159.8
233 1.237756113 158.62
234 1.339447054 157.48
235 1.383181118 156.3
236 1.213781005 155.12
237 1.310221259 154.01
238 1.344108343 152.81
239 1.367520862 151.66
240 1.197841162 150.49
241 1.219617617 149.28
242 1.299869434 148.11
243 1.370740857 146.95
244 1.175491535 145.83
245 1.272503374 144.68
246 1.251364988 143.52
247 1.321138129 142.3
248 1.127328278 141.16
249 1.319040773 139.94
250 1.118599826 138.74
251 1.312986113 137.64
252 1.392439005 136.41
253 1.197514718 135.29
254 1.218054343 134.14
255 1.230533733 132.94
256 1.209399639 131.82
257 1.362942371 130.63
258 1.365576729 129.47
259 1.235870422 128.24
260 1.250791647 127.08
261 1.407273491 125.89
262 1.279498015 124.77
263 1.419950309 123.67
264 1.343802584 122.51
265 1.359908615 121.28
266 1.221997022 120.16
267 1.406570776 118.98
268 1.32583614  117.77
269 1.456010534 116.59
270 1.446890774 115.47
271 1.486626504 114.25
272 1.271696732 113.07
273 1.123066893 111.94

1 个答案:

答案 0 :(得分:1)

如下所示?

# cut the flow data into range and add that into new "group" column
df$group <- cut(df$flow, c(0.1,1.5,max(df$flow)), labels=c("group1","group2"))
# plot the graph
library(ggplot2); library(dplyr)
ggplot(df, aes(x=idNr, y=flow)) +
  geom_point(data = df %>% filter(group == "group1"), aes(colour=flow)) + 
  scale_colour_gradient(low="green", high="red", name="Not Outliers") +
  geom_point(data = df %>% filter(group == "group2"), aes(size="Outliers"), colour="blue") +
  guides(size = guide_legend("Outliers"))

enter image description here

修改

来自OP的评论。 如果使用dep作为Y轴,即用代码中的dep替换flow(对于ggplot), 图表将是

enter image description here