如何使用R来制作颜色强度图

时间:2014-11-02 19:22:00

标签: r graph plot

我从移动的仪器中通过水获取了一些数据。仪器以Z字形方式移动,每0.5秒记录一次流量数据。

我需要制作一个图表,显示仪器路径上的流量,每种流量值都有不同的颜色。

如何使用R绘制图表?

以下是我的一些数据:

idNr    flow    dep
27  0.288261301 4.04
28  0.321201425 3.96
29  0.348002863 4.05
30  0.266207609 3.98
31  0.344623682 3.98
32  0.33590977  4.02
33  0.333196711 3.98
34  0.443371838 4.08
35  0.751650508 4.35
36  1.026660332 5.15
37  1.79303221  6.52
38  1.804413243 8.04
39  1.773816905 9.55
40  1.782303493 10.99
41  1.726813914 12.49
42  1.61061413  13.95
43  1.747734972 15.44
44  1.619344989 16.88
45  1.527087967 18.37
46  1.552443997 19.84
47  1.580849856 21.36
48  1.47038517  22.8
49  1.392708417 24.28
50  1.56442883  25.78
51  1.777948528 27.22
52  1.802147241 28.7
53  1.87299915  30.2
54  2.053852522 31.7
55  1.642625947 33.18
56  1.427217507 34.62
57  1.52030689  36.05
58  1.417431073 37.55
59  1.443192082 39.1
60  1.34374145  40.56
61  1.421155629 42.01
62  1.333494728 43.58
63  1.3194019   45.03
64  1.394158603 46.62
65  1.429844828 48.08
66  1.367911241 49.58
67  1.355840925 51.02
68  1.378465281 52.55
69  1.523250886 53.91
70  1.365535668 55.61
71  1.396372615 57.04
72  1.347452677 58.57
73  1.382778102 60.02
74  1.455112272 61.48
75  1.350807161 63.02
76  1.386283066 64.42
77  1.390035765 65.97
78  1.383424985 67.4
79  1.395385154 68.96
80  1.381371239 70.49
81  1.400707773 71.98
82  1.476066775 73.48
83  1.284056739 75.03
84  1.475329288 76.46
85  1.459387313 78.01
86  1.465585987 79.61
87  1.431249165 81.19
88  1.357601114 82.55
89  1.382301557 84.12
90  1.445689198 85.61
91  1.36922513  87.16
92  1.520221768 88.68
93  1.498713299 90.21
94  1.598120373 91.74
95  1.434218834 93.23
96  1.526169617 94.77
97  1.53240429  96.32
98  1.593795786 97.73
99  1.60067114  99.26
100 1.699682725 100.85
101 1.656267698 102.39
102 1.688246548 103.97
103 1.665317693 105.45
104 1.710451732 106.94
105 1.558604843 108.5
106 1.682163929 109.96
107 1.754686611 111.43
108 1.451731985 112.94
109 1.75889143  114.49
110 1.578577562 115.98
111 1.660725181 117.43
112 1.638376473 119.05
113 1.701685385 120.54
114 1.603928968 122.06
115 1.716673882 123.55
116 1.721613119 125.04
117 1.520097264 126.52
118 1.673504264 128.04
119 1.651535476 129.54
120 1.716307179 131.06
121 1.661417444 132.56
122 1.807044943 134.09
123 1.670927777 135.61
124 1.816092103 137.15
125 1.61581054  138.66
126 1.443289015 140.17
127 1.548887918 141.65
128 1.742922886 143.19
129 1.407817467 144.64
130 1.537282981 146.2
131 1.605707701 147.66
132 1.595514766 149.11
133 1.664969522 150.64
134 1.597832102 152.2
135 1.656365329 153.63
136 1.475701825 155.17
137 1.584298389 156.64
138 1.511851004 158.09
139 1.81195684  159.64
140 1.429699891 161.16
141 1.453907433 162.64
142 1.583450822 164.13
143 1.670092861 165.61
144 1.564082726 167.12
145 1.705749786 168.64
146 1.617373325 170.1
147 1.705749786 171.67
148 1.750116174 173.24
149 1.612112174 174.71
150 1.543739041 176.19
151 1.658449408 177.8
152 1.544094384 179.26
153 1.660865163 180.72
154 1.718616091 182.32
155 1.652198157 183.8
156 1.663230727 185.21
157 1.760015837 186.74
158 1.543345815 188.16
159 1.518992563 189.66
160 1.719743279 191.14
161 1.871325988 192.63
162 1.338309201 194.15
163 1.834802202 195.66
164 1.900303456 197.19
165 1.789994802 198.73
166 1.641265789 200.15
167 1.711407354 201.66
168 1.777665955 203.12
169 1.650013219 204.61
170 1.752274015 206.09
171 1.769734944 207.59
172 1.63480019  209.04
173 1.67727874  210.53
174 1.661860415 212.01
175 1.670834431 213.51
176 1.875008828 214.91
177 1.198086144 216.41
178 1.473233127 217.84
179 1.401750052 219.35
180 1.465064864 220.81
181 1.507361683 222.31
182 1.594120168 223.76
183 1.603827938 225.28
184 1.836556292 226.72
185 1.778422956 228.19
186 1.644971831 229.7
187 1.803737202 231.17
188 1.828251113 232.68
189 1.762103594 234.16
190 1.659823074 235.6
191 1.894313483 237.05
192 1.814170041 238.56
193 1.887235594 239.99
194 1.941720868 241.54
195 1.948726387 242.95
196 1.563589543 244.41
197 2.066101568 245.9
198 1.880538604 247.35
199 1.728849162 248.83
200 1.653487854 250.29
201 1.79743983  251.68
202 1.871167606 253.23
203 2.080688007 254.73
204 1.929135455 256.02
205 1.911069255 257.82
206 1.989423875 259.3
207 1.990416392 260.79
208 2.114887554 262.26
209 1.906502828 263.69
210 1.85085669  265.23
211 1.831357625 266.45
212 1.045764375 266.63
213 0.917485268 266.81
214 0.569920704 266.97
215 0.622531097 267.12
216 0.256491127 267.56
217 0.274736316 267.07
218 0.292981505 266.97
219 0.214553306 266.97
220 0.136125106 267.07
221 0.160799901 267.07
222 0.185474696 267.02
223 0.210149491 267.05
224 0.234824285 267.18
225 0.25949908  267.09
226 0.284173875 267.07
227 0.30884867  267.09
228 0.333523464 267.22
229 0.358198259 267.14
230 0.382873054 267.12
231 0.407547849 267.03
232 0.600179663 266.73
233 0.433797472 266.11
234 1.060132593 265.09
235 1.425310466 264.15
236 1.486875715 263.14
237 1.43689659  262.02
238 1.431465999 260.75
239 1.583936163 259.53
240 1.473233127 258.31
241 1.531834262 257.17
242 1.533104902 255.91
243 1.328999131 254.8
244 1.421761697 253.69
245 1.335436257 252.51
246 1.419856749 251.32
247 1.3703995   250.15
248 1.408783282 248.96
249 1.517088222 247.77
250 1.343802584 246.62
251 1.421537306 245.37
252 1.40061345  244.24
253 1.272161015 243.04
254 1.406138921 241.84
255 1.085843236 240.68
256 1.33602153  239.51
257 1.388280895 238.34
258 1.529552382 237.13
259 1.369493364 235.92
260 1.483642587 234.77
261 1.32851338  233.57
262 1.44039718  232.31
263 1.496418268 231.13
264 1.165322973 229.97
265 1.106764899 228.73
266 1.329991043 227.55
267 1.207740991 226.4
268 1.235528323 225.22
269 1.306827536 224.05
270 1.143623212 222.81
271 1.441714487 221.66
272 1.232362719 220.44
273 1.383297901 219.22
274 1.352388645 218.1
275 1.311460327 216.89
276 1.321217162 215.72
277 1.207279506 214.54
278 1.398024867 213.36
279 1.213781005 212.17
280 1.261582854 210.99
281 1.25985833  209.84
282 1.286305023 208.73
283 1.182046703 207.58
284 1.184988693 206.45
285 1.402951933 205.31
286 1.192968302 204.19
287 1.196836091 203.12
288 1.32083886  201.98
289 1.253255036 200.76
290 1.317613352 199.63
291 1.18891426  198.5
292 1.112625424 197.37
293 1.449004681 196.23
294 1.221578748 195.05
295 1.08139601  193.89
296 1.124301897 192.79
297 1.317373248 191.67
298 0.752773451 190.53
299 1.286574964 189.41
300 1.221500152 188.31
301 1.277374406 187.24
302 1.14505629  186.12
303 1.114030657 184.93
304 1.156791522 183.85
305 1.339019098 182.71
306 1.072565891 181.58
307 1.219754186 180.44
308 1.176963397 179.29
309 1.311925665 178.2
310 1.106051874 176.99
311 1.210041464 175.82
312 1.08161895  174.75
313 1.236070783 173.61
314 1.249614259 172.45
315 1.129300446 171.35
316 1.091558486 170.16
317 1.191516344 169.05
318 1.127521887 167.92
319 1.218621558 166.77
320 1.213781005 165.66
321 1.128293182 164.56
322 1.088186282 163.4
323 1.137727115 162.3
324 1.127388814 161.14
325 1.12490278  160.04
326 1.161036195 158.9
327 1.151329101 157.69
328 1.15757108  156.62
329 1.021796004 155.52
330 1.209076674 154.36
331 1.140870746 153.2
332 1.216107261 152.13
333 1.143405517 150.94
334 1.215779458 149.84
335 1.197327517 148.74
336 1.160052933 147.56
337 1.15880757  146.43
338 1.140225768 145.32
339 1.150143952 144.23
340 1.181602396 143.07
341 1.262274239 141.98
342 1.150799931 140.89
343 1.190711665 139.69
344 1.192584323 138.56
345 1.122635588 137.42
346 1.17500199  136.32
347 1.23807517  135.17
348 1.237353656 134.06
349 1.186746005 132.94
350 1.194924674 131.84
351 1.259003717 130.69
352 1.19677967  129.59
353 1.194242503 128.47
354 1.220205134 127.36
355 1.127990121 126.24
356 1.213781005 125.12
357 1.225973285 123.98
358 1.084756214 122.92
359 1.16161302  121.79
360 1.133334361 120.69
361 1.103127249 119.47
362 1.213781005 118.39
363 1.145836506 117.33
364 1.20781161  116.23
365 1.268126196 115.11
366 1.246070826 113.87
367 1.152060081 112.76
368 1.115006535 111.65
369 1.317280173 110.52
370 1.122671561 109.52
371 1.023553395 108.36
372 1.238632991 107.22
373 1.235124322 106.09
374 1.345223487 104.93
375 1.129630965 103.82
376 1.203403012 102.73
377 1.218779527 101.63
378 1.083551945 100.55
379 1.217290587 99.34
380 1.189233024 98.26
381 1.181995069 97.11
382 1.178651465 95.98
383 1.167093928 94.92
384 1.151487191 93.77
385 1.117688875 92.67
386 1.20046723  91.55
387 1.110913079 90.4
388 1.159221326 89.29
389 1.129196317 88.25
390 1.147979401 87.2
391 1.063138489 86.2
392 1.039855855 85.19
393 1.055872599 84.26
394 1.021566005 83.23
395 1.031262374 82.26
396 1.036922271 81.3
397 1.071390137 80.36
398 1.051908853 79.33
399 1.05363193  78.37
400 1.049712054 77.42
401 1.065736139 76.43
402 1.040108714 75.45
403 1.036886439 74.46
404 1.034880221 73.49
405 1.026660332 72.52
406 1.045490737 71.48
407 1.041245049 70.52
408 1.043207468 69.59
409 1.040543451 68.63
410 1.048860034 67.59
411 1.051861014 66.62
412 1.037198757 65.68
413 1.046622175 64.69
414 1.030435095 63.77
415 1.030156191 62.77
416 1.03762919  61.78
417 1.050493282 60.81
418 1.038155437 59.82
419 1.045090365 58.8
420 1.043834133 57.86
421 1.029653777 56.85
422 1.030381872 55.92
423 1.05024807  54.98
424 1.04567738  54.06
425 1.050961984 53.12
426 1.064207877 52.05
427 1.041433576 51.05
428 1.049447154 49.99
429 1.030094049 49.05
430 1.061292117 48.12
431 1.03820263  47.11
432 1.047136302 46.12
433 1.043207468 45.15
434 1.031741777 44.27
435 1.042840882 43.31
436 1.023755536 42.17
437 1.039746288 41.24
438 1.01600053  40.31
439 1.043669864 39.36
440 1.034305507 38.36
441 1.037222818 37.37
442 1.071353563 36.34
443 1.041574131 35.4

2 个答案:

答案 0 :(得分:1)

不完全是你所要求的,但这表明随着设备的上升,流量明显降低 - 颜色并没有真正展示IMO。

library(ggplot2)
data$direction <- with(data,ifelse(idNr<idNr[which.max(dep)],
                                   "Descending","Ascending"))
ggplot(data,aes(x=dep,y=flow))+
  geom_path(aes(color=direction))+
  theme_bw()

答案 1 :(得分:0)

一种可能的方式(假设我已经确定x轴和y轴变量正确dep是&#34;深度&#34; - 这就是为什么我颠倒了y-轴):

library(ggplot2)

gg <- ggplot(dat, aes(x=idNr, y=dep))
gg <- gg + geom_line(aes(color=flow), size=2)
gg <- gg + scale_y_reverse()
gg <- gg + scale_color_gradient(low="blue", high="red")
gg <- gg + theme_bw()
gg

enter image description here

虽然您可能更好地使用cut为流值定义离散断点(以及颜色),而不是指定连续的颜色范围。