├── .gitattributes
├── Data files
├── Dataset1-Media-Example-EDGES.csv
├── Dataset1-Media-Example-NODES.csv
├── Dataset2-Media-User-Example-EDGES.csv
├── Dataset2-Media-User-Example-NODES.csv
├── Dataset3-Airlines-EDGES.csv
├── Dataset3-Airlines-NODES.csv
└── Images
│ ├── news.png
│ ├── puppy.png
│ └── user.png
├── README.md
├── Sunbelt 2016 R Network Visualization Handout.pdf
└── Sunbelt 2016 R Network Visualization Workshop.R
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/Data files/Dataset1-Media-Example-EDGES.csv:
--------------------------------------------------------------------------------
1 | from,to,weight,type
2 | s01,s02,10,hyperlink
3 | s01,s02,12,hyperlink
4 | s01,s03,22,hyperlink
5 | s01,s04,21,hyperlink
6 | s04,s11,22,mention
7 | s05,s15,21,mention
8 | s06,s17,21,mention
9 | s08,s09,11,mention
10 | s08,s09,12,mention
11 | s03,s04,22,hyperlink
12 | s04,s03,23,hyperlink
13 | s01,s15,20,mention
14 | s15,s01,11,hyperlink
15 | s15,s01,11,hyperlink
16 | s16,s17,21,mention
17 | s16,s06,23,hyperlink
18 | s06,s16,21,hyperlink
19 | s09,s10,21,mention
20 | s08,s07,21,mention
21 | s07,s08,22,mention
22 | s07,s10,21,hyperlink
23 | s05,s02,21,hyperlink
24 | s02,s03,21,hyperlink
25 | s02,s01,23,hyperlink
26 | s03,s01,21,hyperlink
27 | s12,s13,22,hyperlink
28 | s12,s14,22,mention
29 | s14,s13,21,mention
30 | s13,s12,21,hyperlink
31 | s05,s09,2,hyperlink
32 | s02,s10,5,hyperlink
33 | s03,s12,1,hyperlink
34 | s04,s06,1,mention
35 | s10,s03,2,hyperlink
36 | s03,s10,2,mention
37 | s04,s12,3,hyperlink
38 | s13,s17,1,mention
39 | s06,s06,1,hyperlink
40 | s14,s11,1,mention
41 | s03,s11,1,hyperlink
42 | s12,s06,2,mention
43 | s04,s17,2,mention
44 | s17,s04,4,hyperlink
45 | s08,s03,2,hyperlink
46 | s03,s08,4,hyperlink
47 | s07,s14,4,mention
48 | s15,s06,4,hyperlink
49 | s15,s04,1,hyperlink
50 | s05,s01,1,mention
51 | s02,s09,1,hyperlink
52 | s03,s05,1,hyperlink
53 | s07,s03,1,mention
54 |
--------------------------------------------------------------------------------
/Data files/Dataset1-Media-Example-NODES.csv:
--------------------------------------------------------------------------------
1 | id,media,media.type,type.label,audience.size
2 | s01,NY Times,1,Newspaper,20
3 | s02,Washington Post,1,Newspaper,25
4 | s03,Wall Street Journal,1,Newspaper,30
5 | s04,USA Today,1,Newspaper,32
6 | s05,LA Times,1,Newspaper,20
7 | s06,New York Post,1,Newspaper,50
8 | s07,CNN,2,TV,56
9 | s08,MSNBC,2,TV,34
10 | s09,FOX News,2,TV,60
11 | s10,ABC,2,TV,23
12 | s11,BBC,2,TV,34
13 | s12,Yahoo News,3,Online,33
14 | s13,Google News,3,Online,23
15 | s14,Reuters.com,3,Online,12
16 | s15,NYTimes.com,3,Online,24
17 | s16,WashingtonPost.com,3,Online,28
18 | s17,AOL.com,3,Online,33
19 |
--------------------------------------------------------------------------------
/Data files/Dataset2-Media-User-Example-EDGES.csv:
--------------------------------------------------------------------------------
1 | ,U01,U02,U03,U04,U05,U06,U07,U08,U09,U10,U11,U12,U13,U14,U15,U16,U17,U18,U19,U20
2 | s01,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
3 | s02,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
4 | s03,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0
5 | s04,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0
6 | s05,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0
7 | s06,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,0,0,0
8 | s07,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0
9 | s08,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0
10 | s09,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1
11 | s10,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0
12 |
--------------------------------------------------------------------------------
/Data files/Dataset2-Media-User-Example-NODES.csv:
--------------------------------------------------------------------------------
1 | id,media,media.type,media.name,audience.size
2 | s01,NYT,1,Newspaper,20
3 | s02,WaPo,1,Newspaper,25
4 | s03,WSJ,1,Newspaper,30
5 | s04,USAT,1,Newspaper,32
6 | s05,LATimes,1,Newspaper,20
7 | s06,CNN,2,TV,56
8 | s07,MSNBC,2,TV,34
9 | s08,FOX ,2,TV,60
10 | s09,ABC,2,TV,23
11 | s10,BBC,2,TV,34
12 | U01,John,NA,NA,NA
13 | U02,Mary,NA,NA,NA
14 | U03,Paul,NA,NA,NA
15 | U04,Ted,NA,NA,NA
16 | U05,Tom,NA,NA,NA
17 | U06,Kate,NA,NA,NA
18 | U07,Ed,NA,NA,NA
19 | U08,Anna,NA,NA,NA
20 | U09,Dan,NA,NA,NA
21 | U10,Nancy,NA,NA,NA
22 | U11,Sandra,NA,NA,NA
23 | U12,Ronda,NA,NA,NA
24 | U13,Sheila,NA,NA,NA
25 | U14,Jim,NA,NA,NA
26 | U15,Jill,NA,NA,NA
27 | U16,Jo,NA,NA,NA
28 | U17,Brian,NA,NA,NA
29 | U18,Jason,NA,NA,NA
30 | U19,Lisa,NA,NA,NA
31 | U20,Dave,NA,NA,NA
32 |
--------------------------------------------------------------------------------
/Data files/Dataset3-Airlines-EDGES.csv:
--------------------------------------------------------------------------------
1 | Source,Target,Freq
2 | 0,109,10
3 | 1,36,10
4 | 1,61,10
5 | 2,152,10
6 | 3,104,10
7 | 4,132,10
8 | 4,168,10
9 | 5,217,10
10 | 7,173,10
11 | 7,177,10
12 | 8,53,10
13 | 9,105,10
14 | 9,106,10
15 | 9,128,10
16 | 9,152,10
17 | 10,8,10
18 | 10,25,10
19 | 10,61,10
20 | 10,70,10
21 | 10,105,10
22 | 10,133,10
23 | 10,223,10
24 | 11,68,10
25 | 11,78,10
26 | 11,106,10
27 | 11,191,10
28 | 12,204,10
29 | 13,179,10
30 | 14,120,10
31 | 14,159,10
32 | 14,172,10
33 | 18,130,10
34 | 19,11,10
35 | 19,112,10
36 | 20,154,10
37 | 21,36,10
38 | 21,49,10
39 | 21,109,10
40 | 21,111,10
41 | 22,77,10
42 | 22,104,10
43 | 22,106,10
44 | 22,164,10
45 | 24,44,10
46 | 24,45,10
47 | 25,69,10
48 | 27,41,10
49 | 27,98,10
50 | 27,136,10
51 | 27,203,10
52 | 28,120,10
53 | 30,11,10
54 | 30,22,10
55 | 30,168,10
56 | 30,169,10
57 | 31,63,10
58 | 34,45,80
59 | 34,61,80
60 | 35,37,80
61 | 35,69,80
62 | 35,103,80
63 | 35,111,80
64 | 36,84,80
65 | 36,123,80
66 | 37,18,80
67 | 37,78,80
68 | 37,87,80
69 | 37,101,80
70 | 37,157,80
71 | 37,181,80
72 | 37,197,80
73 | 37,213,80
74 | 38,6,80
75 | 38,84,80
76 | 41,0,80
77 | 41,2,80
78 | 41,4,80
79 | 41,9,80
80 | 41,10,80
81 | 41,11,80
82 | 41,19,80
83 | 41,22,80
84 | 41,25,80
85 | 41,28,80
86 | 41,30,80
87 | 41,31,80
88 | 41,35,80
89 | 41,49,80
90 | 41,77,80
91 | 41,131,80
92 | 41,132,80
93 | 41,193,80
94 | 41,214,80
95 | 41,223,80
96 | 41,226,80
97 | 42,18,80
98 | 43,11,80
99 | 43,154,80
100 | 44,21,80
101 | 44,41,80
102 | 44,71,80
103 | 44,77,80
104 | 44,131,80
105 | 45,25,80
106 | 45,41,80
107 | 45,43,80
108 | 45,83,80
109 | 45,123,10
110 | 45,132,10
111 | 45,180,10
112 | 47,18,10
113 | 48,11,10
114 | 48,35,10
115 | 48,41,10
116 | 48,205,10
117 | 49,70,10
118 | 49,138,10
119 | 49,157,10
120 | 49,176,10
121 | 49,182,10
122 | 50,0,10
123 | 50,1,10
124 | 50,2,10
125 | 50,3,10
126 | 50,6,10
127 | 50,8,10
128 | 50,9,10
129 | 50,10,10
130 | 50,11,10
131 | 50,12,10
132 | 50,19,10
133 | 50,20,10
134 | 50,22,10
135 | 50,25,10
136 | 50,27,10
137 | 50,28,10
138 | 50,30,10
139 | 50,31,10
140 | 50,32,10
141 | 50,33,10
142 | 50,34,10
143 | 50,35,10
144 | 50,36,10
145 | 50,37,10
146 | 50,38,10
147 | 50,41,10
148 | 50,44,10
149 | 50,45,10
150 | 50,48,10
151 | 50,49,10
152 | 51,26,10
153 | 53,37,10
154 | 53,48,10
155 | 53,50,10
156 | 53,118,10
157 | 53,152,10
158 | 53,172,10
159 | 53,189,10
160 | 53,226,10
161 | 55,37,10
162 | 55,69,10
163 | 55,105,10
164 | 56,192,10
165 | 57,50,10
166 | 58,50,10
167 | 59,19,10
168 | 59,21,10
169 | 59,50,10
170 | 59,146,10
171 | 59,180,10
172 | 61,30,300
173 | 61,41,300
174 | 61,50,300
175 | 61,70,300
176 | 61,84,300
177 | 61,145,300
178 | 62,40,300
179 | 63,24,300
180 | 65,27,300
181 | 65,48,300
182 | 65,50,300
183 | 65,206,300
184 | 68,17,300
185 | 68,50,300
186 | 68,65,300
187 | 68,106,300
188 | 69,41,300
189 | 69,50,300
190 | 69,87,300
191 | 69,92,300
192 | 69,119,300
193 | 69,125,300
194 | 69,168,300
195 | 69,203,300
196 | 69,213,300
197 | 70,4,300
198 | 70,9,10
199 | 70,11,10
200 | 70,19,10
201 | 70,22,10
202 | 70,37,10
203 | 70,41,10
204 | 70,43,10
205 | 70,44,10
206 | 70,48,10
207 | 70,50,10
208 | 70,56,10
209 | 70,59,10
210 | 70,65,10
211 | 70,69,10
212 | 70,77,10
213 | 70,86,10
214 | 70,133,10
215 | 70,172,10
216 | 70,198,10
217 | 70,211,10
218 | 71,134,10
219 | 72,37,10
220 | 72,51,10
221 | 72,80,10
222 | 72,93,10
223 | 73,50,10
224 | 74,50,10
225 | 74,172,10
226 | 74,185,10
227 | 75,41,10
228 | 75,49,10
229 | 75,50,10
230 | 75,77,10
231 | 75,120,10
232 | 75,128,10
233 | 75,181,10
234 | 76,22,10
235 | 77,9,10
236 | 77,50,10
237 | 77,74,10
238 | 77,111,10
239 | 77,125,10
240 | 78,70,10
241 | 78,84,10
242 | 79,44,10
243 | 79,50,10
244 | 80,0,10
245 | 80,1,10
246 | 80,2,10
247 | 80,4,10
248 | 80,5,10
249 | 80,8,10
250 | 80,9,10
251 | 80,10,10
252 | 80,11,10
253 | 80,14,10
254 | 80,18,10
255 | 80,19,10
256 | 80,20,10
257 | 80,22,10
258 | 80,25,10
259 | 80,27,10
260 | 80,29,10
261 | 80,34,10
262 | 80,35,10
263 | 80,37,10
264 | 80,41,10
265 | 80,43,10
266 | 80,44,10
267 | 80,45,10
268 | 80,48,10
269 | 80,49,10
270 | 80,50,10
271 | 80,52,10
272 | 80,55,10
273 | 80,56,10
274 | 80,67,10
275 | 80,69,10
276 | 80,70,10
277 | 80,75,10
278 | 80,77,10
279 | 80,78,10
280 | 80,79,10
281 | 80,91,10
282 | 80,122,10
283 | 80,125,10
284 | 80,128,10
285 | 80,203,10
286 | 80,219,10
287 | 80,229,10
288 | 81,13,10
289 | 82,44,10
290 | 82,59,10
291 | 82,105,10
292 | 82,157,10
293 | 82,205,10
294 | 82,219,10
295 | 82,229,10
296 | 83,106,10
297 | 84,2,10
298 | 84,9,10
299 | 84,11,10
300 | 84,19,10
301 | 84,25,10
302 | 84,27,10
303 | 84,28,10
304 | 84,35,10
305 | 84,37,10
306 | 84,45,10
307 | 84,48,10
308 | 84,50,10
309 | 84,65,10
310 | 84,69,10
311 | 84,70,10
312 | 84,75,10
313 | 84,77,10
314 | 84,80,10
315 | 84,128,10
316 | 84,150,10
317 | 84,168,10
318 | 84,179,10
319 | 84,181,10
320 | 84,190,10
321 | 84,192,10
322 | 85,172,10
323 | 86,9,10
324 | 86,41,10
325 | 86,49,10
326 | 86,50,10
327 | 86,75,10
328 | 86,80,10
329 | 86,84,10
330 | 87,9,10
331 | 87,10,10
332 | 87,25,10
333 | 87,30,10
334 | 87,41,10
335 | 87,48,10
336 | 87,50,10
337 | 87,65,10
338 | 87,70,10
339 | 87,80,10
340 | 87,84,10
341 | 87,90,10
342 | 87,97,10
343 | 87,194,10
344 | 87,212,10
345 | 87,230,10
346 | 88,32,10
347 | 88,50,10
348 | 88,59,100
349 | 88,61,100
350 | 88,104,100
351 | 89,18,100
352 | 90,45,100
353 | 90,75,100
354 | 90,83,100
355 | 92,80,100
356 | 92,87,100
357 | 92,130,100
358 | 93,50,100
359 | 93,106,100
360 | 93,111,100
361 | 93,157,100
362 | 93,185,100
363 | 94,18,100
364 | 95,41,100
365 | 95,44,150
366 | 95,49,150
367 | 95,50,150
368 | 95,80,150
369 | 96,11,150
370 | 96,27,150
371 | 96,50,150
372 | 96,70,150
373 | 96,80,150
374 | 96,84,150
375 | 96,98,150
376 | 96,106,150
377 | 96,149,10
378 | 97,41,10
379 | 97,50,10
380 | 97,59,10
381 | 97,61,10
382 | 97,68,10
383 | 97,70,10
384 | 97,134,10
385 | 98,12,10
386 | 98,41,10
387 | 98,50,10
388 | 98,72,10
389 | 98,80,10
390 | 98,84,10
391 | 98,93,10
392 | 99,26,10
393 | 100,70,10
394 | 101,41,10
395 | 101,80,10
396 | 101,87,10
397 | 101,191,10
398 | 102,41,10
399 | 102,50,10
400 | 102,70,10
401 | 102,80,10
402 | 102,118,10
403 | 102,127,10
404 | 102,172,10
405 | 102,192,10
406 | 102,194,10
407 | 103,41,10
408 | 103,70,10
409 | 103,82,10
410 | 104,41,10
411 | 104,50,10
412 | 104,82,10
413 | 104,185,10
414 | 104,223,10
415 | 105,2,10
416 | 105,35,10
417 | 105,45,10
418 | 105,50,10
419 | 105,63,10
420 | 105,70,10
421 | 105,80,10
422 | 105,84,10
423 | 105,87,10
424 | 105,102,10
425 | 105,104,10
426 | 105,115,10
427 | 105,180,10
428 | 105,213,10
429 | 106,35,10
430 | 106,41,10
431 | 106,50,10
432 | 106,70,10
433 | 106,79,10
434 | 106,80,10
435 | 106,84,10
436 | 106,115,10
437 | 107,80,10
438 | 109,20,10
439 | 109,24,10
440 | 109,41,10
441 | 109,45,10
442 | 109,48,10
443 | 109,49,10
444 | 109,50,10
445 | 109,70,10
446 | 109,80,10
447 | 109,84,10
448 | 109,87,10
449 | 109,105,10
450 | 109,106,10
451 | 109,200,10
452 | 110,13,10
453 | 110,70,10
454 | 110,80,10
455 | 111,41,10
456 | 111,44,10
457 | 111,50,10
458 | 111,80,10
459 | 111,82,10
460 | 111,84,10
461 | 111,97,10
462 | 111,125,10
463 | 111,168,10
464 | 111,224,10
465 | 112,50,10
466 | 112,84,10
467 | 112,175,10
468 | 114,22,10
469 | 114,50,10
470 | 115,44,10
471 | 115,45,10
472 | 115,50,10
473 | 115,54,10
474 | 115,84,10
475 | 115,87,10
476 | 115,127,10
477 | 115,200,10
478 | 115,203,10
479 | 117,0,10
480 | 117,80,10
481 | 118,7,10
482 | 118,24,10
483 | 118,50,10
484 | 118,66,10
485 | 118,70,10
486 | 118,80,10
487 | 118,84,10
488 | 118,87,10
489 | 118,109,10
490 | 118,115,10
491 | 119,37,10
492 | 119,41,10
493 | 119,50,10
494 | 119,70,10
495 | 119,80,10
496 | 119,95,10
497 | 119,211,10
498 | 120,2,10
499 | 120,9,10
500 | 120,36,10
501 | 120,41,10
502 | 120,50,10
503 | 120,80,10
504 | 120,84,10
505 | 120,92,10
506 | 120,96,10
507 | 120,229,10
508 | 121,70,10
509 | 122,41,10
510 | 122,145,10
511 | 122,182,10
512 | 123,41,10
513 | 123,50,10
514 | 123,80,10
515 | 123,84,10
516 | 123,87,10
517 | 124,64,10
518 | 125,35,10
519 | 125,50,10
520 | 125,59,10
521 | 125,119,10
522 | 126,70,10
523 | 127,0,10
524 | 127,50,10
525 | 127,70,10
526 | 127,80,10
527 | 127,84,10
528 | 127,87,10
529 | 127,106,10
530 | 127,109,10
531 | 127,118,10
532 | 127,189,10
533 | 128,14,10
534 | 128,20,10
535 | 128,31,10
536 | 128,41,10
537 | 128,49,10
538 | 128,50,10
539 | 128,70,10
540 | 128,82,10
541 | 128,168,10
542 | 128,207,10
543 | 129,80,10
544 | 130,0,10
545 | 130,5,10
546 | 130,9,10
547 | 130,10,10
548 | 130,11,10
549 | 130,13,50
550 | 130,14,50
551 | 130,19,50
552 | 130,22,50
553 | 130,25,50
554 | 130,34,50
555 | 130,35,50
556 | 130,37,50
557 | 130,41,50
558 | 130,44,50
559 | 130,45,50
560 | 130,46,50
561 | 130,48,50
562 | 130,49,50
563 | 130,50,50
564 | 130,55,50
565 | 130,59,50
566 | 130,61,50
567 | 130,65,50
568 | 130,69,50
569 | 130,70,50
570 | 130,76,50
571 | 130,77,50
572 | 130,78,50
573 | 130,79,50
574 | 130,80,50
575 | 130,81,50
576 | 130,82,50
577 | 130,84,50
578 | 130,86,50
579 | 130,87,50
580 | 130,96,50
581 | 130,97,50
582 | 130,101,50
583 | 130,105,50
584 | 130,106,50
585 | 130,109,50
586 | 130,110,50
587 | 130,111,50
588 | 130,113,50
589 | 130,115,50
590 | 130,118,50
591 | 130,119,50
592 | 130,120,50
593 | 130,122,50
594 | 130,127,50
595 | 130,128,50
596 | 131,50,50
597 | 131,80,50
598 | 131,130,50
599 | 131,219,50
600 | 132,20,50
601 | 132,48,50
602 | 132,50,50
603 | 132,70,50
604 | 132,80,50
605 | 132,84,50
606 | 132,91,50
607 | 132,118,50
608 | 132,130,50
609 | 133,46,50
610 | 133,130,50
611 | 134,36,50
612 | 134,50,50
613 | 134,80,50
614 | 134,84,50
615 | 134,135,50
616 | 134,171,50
617 | 134,192,50
618 | 134,193,50
619 | 135,10,50
620 | 135,70,50
621 | 135,80,50
622 | 135,97,50
623 | 136,0,50
624 | 136,2,50
625 | 136,4,50
626 | 136,8,50
627 | 136,9,50
628 | 136,10,50
629 | 136,11,50
630 | 136,16,50
631 | 136,18,50
632 | 136,20,50
633 | 136,21,50
634 | 136,24,50
635 | 136,25,50
636 | 136,26,50
637 | 136,30,50
638 | 136,31,50
639 | 136,33,50
640 | 136,34,50
641 | 136,35,50
642 | 136,36,50
643 | 136,37,50
644 | 136,39,50
645 | 136,40,50
646 | 136,41,50
647 | 136,43,50
648 | 136,44,50
649 | 136,45,50
650 | 136,48,50
651 | 136,49,50
652 | 136,50,50
653 | 136,51,50
654 | 136,53,50
655 | 136,54,50
656 | 136,59,50
657 | 136,62,50
658 | 136,63,50
659 | 136,64,50
660 | 136,65,50
661 | 136,68,50
662 | 136,69,50
663 | 136,70,50
664 | 136,71,50
665 | 136,72,50
666 | 136,74,50
667 | 136,75,50
668 | 136,79,50
669 | 136,80,50
670 | 136,82,50
671 | 136,83,50
672 | 136,84,50
673 | 136,85,50
674 | 136,87,50
675 | 136,90,50
676 | 136,92,50
677 | 136,93,50
678 | 136,97,50
679 | 136,98,50
680 | 136,99,50
681 | 136,101,50
682 | 136,102,50
683 | 136,103,50
684 | 136,104,50
685 | 136,105,50
686 | 136,106,50
687 | 136,109,50
688 | 136,111,50
689 | 136,114,50
690 | 136,115,50
691 | 136,118,50
692 | 136,119,50
693 | 136,120,50
694 | 136,124,50
695 | 136,125,50
696 | 136,127,50
697 | 136,128,50
698 | 136,130,50
699 | 136,132,50
700 | 136,133,50
701 | 136,134,50
702 | 136,135,50
703 | 136,210,50
704 | 137,136,50
705 | 137,171,50
706 | 138,80,50
707 | 138,115,50
708 | 138,130,50
709 | 139,118,50
710 | 140,99,50
711 | 140,136,50
712 | 141,9,50
713 | 141,134,50
714 | 141,136,50
715 | 141,224,50
716 | 142,70,50
717 | 143,18,50
718 | 144,18,50
719 | 145,13,50
720 | 145,70,50
721 | 145,130,50
722 | 146,136,50
723 | 146,176,50
724 | 147,136,50
725 | 148,118,50
726 | 149,50,50
727 | 149,210,50
728 | 149,215,50
729 | 150,50,50
730 | 151,50,50
731 | 151,136,50
732 | 152,1,50
733 | 152,41,50
734 | 152,50,50
735 | 152,70,50
736 | 152,80,50
737 | 152,82,50
738 | 152,84,50
739 | 152,85,50
740 | 152,95,50
741 | 152,102,50
742 | 152,130,50
743 | 152,136,50
744 | 152,229,50
745 | 153,136,50
746 | 154,0,50
747 | 154,2,50
748 | 154,4,50
749 | 154,8,50
750 | 154,9,50
751 | 154,11,50
752 | 154,19,50
753 | 154,22,50
754 | 154,25,50
755 | 154,27,50
756 | 154,28,50
757 | 154,34,50
758 | 154,35,50
759 | 154,37,50
760 | 154,41,50
761 | 154,44,50
762 | 154,48,50
763 | 154,50,50
764 | 154,59,50
765 | 154,65,50
766 | 154,69,50
767 | 154,70,50
768 | 154,75,50
769 | 154,77,50
770 | 154,80,50
771 | 154,84,50
772 | 154,87,50
773 | 154,95,50
774 | 154,97,50
775 | 154,98,50
776 | 154,103,50
777 | 154,105,50
778 | 154,106,50
779 | 154,111,50
780 | 154,118,50
781 | 154,119,50
782 | 154,120,50
783 | 154,123,50
784 | 154,127,50
785 | 154,128,50
786 | 154,130,50
787 | 154,132,50
788 | 154,134,50
789 | 154,135,50
790 | 154,136,50
791 | 154,152,50
792 | 155,80,50
793 | 156,24,50
794 | 157,41,50
795 | 157,50,50
796 | 157,53,50
797 | 157,70,50
798 | 157,80,50
799 | 157,136,50
800 | 157,154,50
801 | 159,50,50
802 | 159,70,50
803 | 159,72,50
804 | 159,87,50
805 | 159,130,50
806 | 159,136,50
807 | 159,168,50
808 | 160,70,50
809 | 160,80,50
810 | 161,39,50
811 | 161,136,50
812 | 162,70,50
813 | 162,80,50
814 | 163,20,50
815 | 163,45,50
816 | 163,50,50
817 | 163,70,50
818 | 163,80,50
819 | 163,84,50
820 | 163,87,50
821 | 163,106,50
822 | 163,118,50
823 | 163,127,50
824 | 163,130,50
825 | 163,131,50
826 | 163,132,50
827 | 163,136,50
828 | 163,154,50
829 | 163,192,50
830 | 163,195,50
831 | 164,41,50
832 | 164,50,50
833 | 164,53,50
834 | 164,80,50
835 | 164,128,50
836 | 164,136,50
837 | 164,185,50
838 | 164,215,50
839 | 165,35,50
840 | 165,41,50
841 | 165,50,50
842 | 165,70,50
843 | 165,80,50
844 | 165,84,50
845 | 165,106,50
846 | 165,154,50
847 | 168,37,50
848 | 168,41,50
849 | 168,48,50
850 | 168,50,50
851 | 168,70,50
852 | 168,80,50
853 | 168,87,50
854 | 168,96,50
855 | 168,103,50
856 | 168,106,50
857 | 168,130,50
858 | 168,136,50
859 | 168,195,50
860 | 169,41,50
861 | 169,49,50
862 | 169,50,50
863 | 169,70,50
864 | 169,80,50
865 | 169,130,50
866 | 169,136,50
867 | 169,154,50
868 | 169,159,50
869 | 170,136,50
870 | 171,19,10
871 | 171,30,10
872 | 171,41,100
873 | 171,44,100
874 | 171,49,100
875 | 171,50,100
876 | 171,70,100
877 | 171,80,100
878 | 171,86,100
879 | 171,130,100
880 | 171,136,100
881 | 171,154,100
882 | 171,219,100
883 | 172,12,100
884 | 172,41,100
885 | 172,50,100
886 | 172,55,100
887 | 172,80,100
888 | 172,86,100
889 | 172,96,100
890 | 172,109,100
891 | 172,120,100
892 | 172,130,100
893 | 172,136,100
894 | 172,154,100
895 | 172,176,100
896 | 172,207,100
897 | 172,208,100
898 | 173,23,100
899 | 173,24,100
900 | 173,41,100
901 | 173,48,100
902 | 173,60,100
903 | 173,65,100
904 | 173,69,100
905 | 173,70,100
906 | 173,80,100
907 | 173,82,100
908 | 173,103,100
909 | 173,108,100
910 | 173,118,100
911 | 173,127,100
912 | 173,135,100
913 | 173,136,100
914 | 173,154,100
915 | 173,158,100
916 | 173,160,100
917 | 173,162,100
918 | 173,167,100
919 | 174,24,100
920 | 175,2,100
921 | 175,50,100
922 | 175,105,100
923 | 175,130,100
924 | 175,136,100
925 | 176,41,100
926 | 176,50,100
927 | 176,70,100
928 | 176,80,100
929 | 176,87,100
930 | 176,106,100
931 | 176,130,100
932 | 176,136,100
933 | 176,138,100
934 | 176,154,100
935 | 176,159,100
936 | 176,175,100
937 | 176,200,100
938 | 177,118,100
939 | 177,173,100
940 | 178,80,100
941 | 178,154,100
942 | 179,35,100
943 | 179,122,100
944 | 179,130,100
945 | 179,217,100
946 | 180,70,100
947 | 180,80,100
948 | 180,130,100
949 | 180,169,100
950 | 180,171,100
951 | 181,50,100
952 | 181,93,100
953 | 181,136,100
954 | 182,50,100
955 | 182,70,100
956 | 182,128,100
957 | 182,130,100
958 | 182,171,100
959 | 183,70,100
960 | 183,80,100
961 | 183,118,100
962 | 183,173,100
963 | 184,18,100
964 | 185,41,100
965 | 185,50,100
966 | 185,80,100
967 | 185,84,100
968 | 185,86,100
969 | 185,114,100
970 | 185,130,100
971 | 185,136,100
972 | 185,154,100
973 | 185,212,100
974 | 186,30,100
975 | 186,50,100
976 | 186,80,100
977 | 187,173,100
978 | 188,118,100
979 | 188,173,100
980 | 189,10,100
981 | 189,20,100
982 | 189,21,100
983 | 189,24,100
984 | 189,41,100
985 | 189,45,100
986 | 189,49,100
987 | 189,50,100
988 | 189,70,100
989 | 189,80,10
990 | 189,84,10
991 | 189,87,10
992 | 189,106,10
993 | 189,118,10
994 | 189,130,10
995 | 189,134,10
996 | 189,136,10
997 | 189,154,10
998 | 189,173,30
999 | 189,200,30
1000 | 190,70,300
1001 | 190,80,300
1002 | 190,120,300
1003 | 190,130,300
1004 | 190,171,300
1005 | 190,172,300
1006 | 191,50,300
1007 | 191,70,300
1008 | 191,80,10
1009 | 191,134,10
1010 | 191,136,10
1011 | 191,173,10
1012 | 192,9,10
1013 | 192,11,400
1014 | 192,18,400
1015 | 192,24,10
1016 | 192,44,10
1017 | 192,48,10
1018 | 192,50,10
1019 | 192,59,10
1020 | 192,63,10
1021 | 192,66,10
1022 | 192,68,10
1023 | 192,70,10
1024 | 192,71,10
1025 | 192,80,10
1026 | 192,82,10
1027 | 192,83,10
1028 | 192,90,10
1029 | 192,103,10
1030 | 192,111,10
1031 | 192,118,10
1032 | 192,127,10
1033 | 192,135,10
1034 | 192,136,10
1035 | 192,137,10
1036 | 192,148,10
1037 | 192,152,10
1038 | 192,154,10
1039 | 192,160,10
1040 | 192,162,10
1041 | 192,168,10
1042 | 192,172,10
1043 | 192,173,10
1044 | 192,176,10
1045 | 192,181,10
1046 | 192,183,10
1047 | 192,189,10
1048 | 192,191,10
1049 | 193,0,10
1050 | 193,50,10
1051 | 193,53,10
1052 | 193,70,10
1053 | 193,80,10
1054 | 193,130,10
1055 | 193,136,10
1056 | 193,154,10
1057 | 194,25,10
1058 | 194,41,10
1059 | 194,50,10
1060 | 194,70,10
1061 | 194,109,10
1062 | 194,115,10
1063 | 194,118,10
1064 | 194,136,10
1065 | 194,154,10
1066 | 194,173,10
1067 | 194,189,10
1068 | 194,192,10
1069 | 195,41,10
1070 | 195,50,200
1071 | 195,69,200
1072 | 195,70,200
1073 | 195,80,200
1074 | 195,84,200
1075 | 195,102,200
1076 | 195,109,200
1077 | 195,115,200
1078 | 195,118,200
1079 | 195,136,200
1080 | 195,146,200
1081 | 195,154,200
1082 | 195,173,200
1083 | 195,192,200
1084 | 196,118,200
1085 | 197,41,200
1086 | 197,50,200
1087 | 197,80,200
1088 | 197,154,200
1089 | 198,44,200
1090 | 198,50,200
1091 | 198,80,200
1092 | 198,130,200
1093 | 198,136,200
1094 | 198,152,200
1095 | 198,154,200
1096 | 199,50,200
1097 | 199,136,200
1098 | 199,221,200
1099 | 200,15,200
1100 | 200,17,200
1101 | 200,18,200
1102 | 200,23,200
1103 | 200,24,200
1104 | 200,41,200
1105 | 200,48,200
1106 | 200,50,200
1107 | 200,60,200
1108 | 200,63,200
1109 | 200,65,200
1110 | 200,66,200
1111 | 200,68,200
1112 | 200,69,200
1113 | 200,70,200
1114 | 200,71,200
1115 | 200,80,200
1116 | 200,83,200
1117 | 200,84,200
1118 | 200,90,200
1119 | 200,103,200
1120 | 200,116,200
1121 | 200,118,200
1122 | 200,127,200
1123 | 200,130,200
1124 | 200,135,200
1125 | 200,136,200
1126 | 200,137,200
1127 | 200,146,200
1128 | 200,148,200
1129 | 200,154,200
1130 | 200,156,200
1131 | 200,160,200
1132 | 200,162,200
1133 | 200,166,200
1134 | 200,173,200
1135 | 200,174,200
1136 | 200,183,200
1137 | 200,187,200
1138 | 200,188,200
1139 | 200,191,200
1140 | 200,192,200
1141 | 200,193,200
1142 | 200,194,200
1143 | 200,195,200
1144 | 201,113,200
1145 | 201,130,200
1146 | 202,79,200
1147 | 202,136,200
1148 | 202,147,200
1149 | 203,10,200
1150 | 203,41,200
1151 | 203,50,200
1152 | 203,70,200
1153 | 203,84,200
1154 | 203,109,200
1155 | 203,130,200
1156 | 203,136,200
1157 | 203,154,200
1158 | 203,168,200
1159 | 203,173,200
1160 | 203,189,200
1161 | 203,192,200
1162 | 203,200,200
1163 | 204,41,200
1164 | 204,50,200
1165 | 204,57,200
1166 | 204,80,200
1167 | 204,88,200
1168 | 204,136,200
1169 | 204,186,200
1170 | 205,41,200
1171 | 205,50,200
1172 | 205,69,200
1173 | 205,70,200
1174 | 205,80,200
1175 | 205,84,200
1176 | 205,87,200
1177 | 205,130,200
1178 | 205,136,200
1179 | 205,154,200
1180 | 205,173,200
1181 | 205,175,200
1182 | 206,24,200
1183 | 206,102,200
1184 | 206,136,200
1185 | 206,173,200
1186 | 206,192,200
1187 | 206,200,200
1188 | 207,28,200
1189 | 207,45,200
1190 | 207,50,200
1191 | 207,70,200
1192 | 207,130,200
1193 | 207,131,200
1194 | 207,136,200
1195 | 207,169,200
1196 | 208,10,200
1197 | 208,50,200
1198 | 208,149,200
1199 | 209,200,200
1200 | 210,50,200
1201 | 210,80,200
1202 | 210,84,200
1203 | 210,87,200
1204 | 210,111,200
1205 | 210,119,200
1206 | 210,154,200
1207 | 211,20,200
1208 | 211,41,200
1209 | 211,50,200
1210 | 211,84,200
1211 | 211,106,200
1212 | 211,134,200
1213 | 211,154,200
1214 | 212,44,200
1215 | 212,80,200
1216 | 212,111,200
1217 | 212,130,200
1218 | 212,152,200
1219 | 213,20,200
1220 | 213,41,200
1221 | 213,50,200
1222 | 213,70,200
1223 | 213,80,200
1224 | 213,84,200
1225 | 213,87,200
1226 | 213,91,200
1227 | 213,130,200
1228 | 213,136,200
1229 | 213,154,200
1230 | 214,50,200
1231 | 215,20,200
1232 | 215,50,200
1233 | 215,150,200
1234 | 216,173,200
1235 | 216,192,200
1236 | 216,200,200
1237 | 217,41,200
1238 | 217,50,200
1239 | 217,130,10
1240 | 217,145,10
1241 | 218,25,10
1242 | 218,59,10
1243 | 218,70,10
1244 | 218,80,10
1245 | 218,136,10
1246 | 218,154,10
1247 | 218,192,10
1248 | 219,34,10
1249 | 219,41,10
1250 | 219,50,10
1251 | 219,70,10
1252 | 219,130,10
1253 | 219,136,10
1254 | 219,154,10
1255 | 220,50,10
1256 | 221,31,10
1257 | 221,32,40
1258 | 221,41,40
1259 | 221,50,40
1260 | 222,200,40
1261 | 223,4,40
1262 | 223,37,40
1263 | 223,45,40
1264 | 223,50,40
1265 | 223,70,40
1266 | 223,74,40
1267 | 223,80,40
1268 | 223,84,40
1269 | 223,130,40
1270 | 223,136,40
1271 | 223,192,40
1272 | 224,93,40
1273 | 224,136,40
1274 | 225,136,40
1275 | 225,170,40
1276 | 226,50,40
1277 | 226,105,40
1278 | 226,136,40
1279 | 227,36,40
1280 | 227,50,40
1281 | 228,50,40
1282 | 228,130,40
1283 | 228,219,40
1284 | 229,41,40
1285 | 229,50,40
1286 | 229,70,40
1287 | 229,77,40
1288 | 229,130,40
1289 | 229,136,40
1290 | 229,154,40
1291 | 229,176,40
1292 | 230,80,40
1293 | 231,80,10
1294 | 232,200,10
1295 | 233,35,10
1296 | 233,136,10
1297 | 234,50,10
1298 | 234,164,10
1299 |
--------------------------------------------------------------------------------
/Data files/Dataset3-Airlines-NODES.csv:
--------------------------------------------------------------------------------
1 | ID,Label,Code,City,latitude,longitude,ToFly,Visits
2 | 0,Adams Field Airport,LIT,"Little Rock, AR",34.729444,-92.224444,0,105
3 | 1,Akron/canton Regional,CAK,"Akron/Canton, OH",40.916111,-81.442222,0,123
4 | 2,Albany International,ALB,Albany,42.733333,-73.8,0,129
5 | 3,Albemarle,CHO,Charlottesville,38.133333,-78.45,1,114
6 | 4,Albuquerque International,ABQ,Albuquerque,35.040278,-106.609167,0,105
7 | 5,Alexandria International,AEX,"Alexandria, LA",31.3275,-92.548611,0,93
8 | 6,Alpena County Regional,APN,Alpena,45.083333,-83.55,0,135
9 | 7,Arcata,ACV,Arcata,40.983333,-124.1,0,123
10 | 8,Asheville Regional Airport,AVL,Fletcher,35.436111,-82.541667,0,105
11 | 9,Austin-bergstrom International,AUS,Austin,30.194444,-97.67,1,90
12 | 10,Austin-straubel Field,GRB,Green Bay,44.483333,-88.133333,1,132
13 | 11,Baltimore/Washington International Thurgood Marshall,BWI,"Baltimore, MD",39.175278,-76.668333,0,117
14 | 12,Bangor International Airport,BGR,Bangor,44.8,-68.816667,0,135
15 | 13,Barkley Regional,PAH,"Paducah, KY",37.060278,-88.773056,0,111
16 | 14,Bay County,PFN,Panama City,30.216667,-85.683333,1,90
17 | 15,Bellingham,BLI,Bellingham,48.8,-122.533333,0,147
18 | 16,Bemidji,BJI,Bemidji,47.516667,-94.933333,0,144
19 | 17,Bert Mooney Airport,BTM,"Butte,",45.954722,-112.4975,0,138
20 | 18,Billings,BIL,Billings,45.8,-108.533333,0,138
21 | 19,Birmingham,BHM,Birmingham,33.566667,-86.75,0,102
22 | 20,Bishop International Airport,FNT,Flint,42.965556,-83.743611,0,129
23 | 21,Bismarck,BIS,Bismarck,46.783333,-100.75,0,141
24 | 22,Blue Grass,LEX,Lexington,38.036389,-84.605833,1,114
25 | 23,Bob Hope,BUR,Burbank,34.2,-118.35,0,102
26 | 24,Boise Air Terminal/Gowen Field,BOI,"Boise, ID",43.564444,-116.222778,0,132
27 | 25,Bradley International,BDL,"Windsor Locks, CT",41.938889,-72.683333,0,126
28 | 26,Brainerd Lakes Regional,BRD,"Brainerd, MN",46.401667,-94.135556,0,138
29 | 27,Buffalo Niagara International,BUF,"Buffalo, NY",42.940556,-78.732222,1,129
30 | 28,Burlington International,BTV,Burlington,44.471944,-73.153333,0,132
31 | 29,Bush Field,AGS,Augusta,33.366667,-81.966667,0,99
32 | 30,Capital City,LAN,Lansing,42.783333,-84.583333,0,129
33 | 31,Cedar Rapids,CID,Cedar Rapids,41.884722,-91.710833,0,126
34 | 32,Central Illinois Regional Airport at Bloomington-Normal,BMI,"Bloomington/Normal, IL",40.477222,-88.915833,0,120
35 | 33,Central Wisconsin,CWA,Wausau,44.769444,-89.683056,0,135
36 | 34,"Charleston, AFB Municipal",CHS,"Charleston, SC",32.898611,-80.040556,1,99
37 | 35,Charlotte Douglas,CLT,Charlotte,35.216667,-80.933333,0,105
38 | 36,Cherry Capital Airport,TVC,Traverse City,44.741389,-85.582222,0,135
39 | 37,Chicago O'hare International,ORD,"Chicago, Il",41.978611,-87.904722,1,126
40 | 38,Chippewa County,CIU,Sault Ste Marie,46.25,-84.466667,0,138
41 | 39,Chippewa Valley Regional Airport,EAU,"Eau Claire, WI",44.865833,-91.484167,0,135
42 | 40,Chisholm,HIB,Chisholm,47.383333,-92.833333,0,141
43 | 41,Cincinnati/northern Kentucky,CVG,"Covington, KY",39.048889,-84.667778,0,117
44 | 42,City County,HVR,Havre,48.55,-109.766667,0,147
45 | 43,Colorado Springs,COS,Colorado Springs,38.816667,-104.716667,0,117
46 | 44,Dallas/Fort Worth International,DFW,"Dallas, TX",32.896944,-97.038056,1,99
47 | 45,Dane County Regional,MSN,Madison,43.139722,-89.3375,0,129
48 | 46,Dannelly Fld,MGM,Montgomery,32.3,-86.4,0,96
49 | 47,Dawson Community,GDV,Glendive,47.133333,-104.683333,0,141
50 | 48,Denver International,DEN,Denver,39.861667,-104.673056,0,120
51 | 49,Des Moines International,DSM,"Des Moines, IA",41.533889,-93.663056,0,126
52 | 50,Detroit Metropolitan Wayne County,DTW,"Detroit, MI",42.2125,-83.353333,0,126
53 | 51,Devils Lake,DVL,Devils Lake,48.116667,-98.9,0,144
54 | 52,Dothan Arpt,DHN,Dothan,31.316667,-85.45,0,93
55 | 53,Duluth International,DLH,Duluth,46.833333,-92.183333,0,141
56 | 54,Eagle County,EGE,Vail/Eagle,39.633333,-106.916667,0,120
57 | 55,Eglin AFB,VPS,"Valparaiso, FL",30.483333,-86.525278,0,90
58 | 56,El Paso International Airport,ELP,El Paso,31.8,-106.383333,0,96
59 | 57,Elmira Corning Regional,ELM,"Corning, NY",42.166667,-76.9,0,126
60 | 58,Emmet County,PLN,Pellston,45.566667,-84.8,0,138
61 | 59,Eppley Airfield,OMA,Omaha,41.3,-95.9,1,123
62 | 60,Eugene,EUG,Eugene,44.116667,-123.216667,0,132
63 | 61,Evansville Regional Airport,EVV,"Evansville, IN",38.036944,-87.5325,0,114
64 | 62,Falls Intl,INL,International Falls,48.566667,-93.4,0,147
65 | 63,Fanning Field,IDA,Idaho Falls,43.516667,-112.066667,0,132
66 | 64,Fort Dodge Regional,FOD,"Fort Dodge, IA",42.551111,-94.191944,0,129
67 | 65,Fort Lauderdale/hollywood International,FLL,"Fort Lauderdale, FL",26.0725,-80.152778,0,78
68 | 66,Fresno Air Terminal Airport,FAT,Fresno,36.766667,-119.716667,1,111
69 | 67,Gainesville Regional,GNV,Gainesville,29.683333,-82.266667,0,90
70 | 68,Gallatin Field,BZN,Bozeman,45.7775,-111.153056,1,138
71 | 69,General Mitchell International,MKE,Milwaukee,42.95,-87.9,1,129
72 | 70,George Bush Intercontinental,IAH,Houston,29.984444,-95.341389,1,90
73 | 71,Glacier Park International,FCA,"Kalispell, MT",48.316667,-114.266667,0,144
74 | 72,Grand Forks,GFK,Grand Forks,47.95,-97.183333,0,144
75 | 73,Greater Binghamton,BGM,"Binghamton, NY",42.208611,-75.979722,0,126
76 | 74,Greater Peoria,PIA,"Peoria, IL",40.666667,-89.683333,0,123
77 | 75,Greater Rochester International,ROC,"Rochester, NY",43.118889,-77.6725,0,129
78 | 76,Greenville,GLH,Greenville,33.477222,-90.985,0,99
79 | 77,Greenville Spartanbur Int'l Airport,GSP,Greenville,34.895556,-82.218889,0,105
80 | 78,Gulfport-Biloxi International,GPT,Gulfport,30.4,-89.066667,0,90
81 | 79,Harrisburg International,MDT,"Harrisburg, PA",40.193611,-76.763333,0,120
82 | 80,Hartsfield-jackson Atlanta International,ATL,"Atlanta, GA",33.636667,-84.428056,1,102
83 | 81,Hattiesburg-Laurel Regional,PIB,"Hattiesburg/Laurel, MS",31.467222,-89.336944,0,93
84 | 82,Hector Field,FAR,Fargo,46.916667,-96.816667,0,141
85 | 83,Helena,HLN,Helena,46.6,-111.983333,0,141
86 | 84,Hopkins International,CLE,Cleveland,41.416667,-81.85,0,123
87 | 85,Houghton County,CMX,Hancock,47.123611,-88.573333,0,141
88 | 86,Huntsville International - Carl T. Jones Field,HSV,"Huntsville, AL",34.637222,-86.775,0,105
89 | 87,Indianapolis International,IND,"Indianapolis, IN",39.717222,-86.294722,1,120
90 | 88,International,ERI,Erie,42.083333,-80.183333,0,126
91 | 89,International,GGW,Glasgow,48.216667,-106.616667,1,144
92 | 90,International,GTF,Great Falls,47.5,-111.366667,1,144
93 | 91,International,EYW,Key West,24.55,-81.766667,1,75
94 | 92,International,MOT,Minot,48.266667,-101.283333,0,144
95 | 93,International,RST,Rochester,43.908333,-92.5,0,132
96 | 94,International,OLF,Wolf Point,48.083333,-105.566667,0,144
97 | 95,Intl Jetport,PWM,Portland,43.65,-70.3,0,132
98 | 96,Jackson-evers,JAN,Jackson,32.311111,-90.075833,0,96
99 | 97,"Jacksonville,",JAX,"Jacksonville, FL",30.416667,-81.633333,0,90
100 | 98,James Cox Dayton Intl,DAY,"Dayton, Oh",39.75,-84.183333,0,120
101 | 99,Jamestown,JMS,Jamestown,46.933333,-98.683333,1,141
102 | 100,Jefferson County,BPT,Beaumont,30.083333,-94.1,0,90
103 | 101,Joe Foss Field Airport,FSD,Sioux Falls,43.581944,-96.741944,0,132
104 | 102,John F Kennedy Intl,JFK,New York,40.633333,-73.783333,0,123
105 | 103,John Wayne,SNA,"Santa Ana, CA",33.666667,-117.866667,0,102
106 | 104,Kalamazoo/Battle Creek Intl,AZO,Kalamazoo,42.235,-85.551944,0,126
107 | 105,Kansas City International Airport,MCI,Kansas City,39.291667,-94.730556,0,117
108 | 106,Kent County Intl,GRR,Grand Rapids,42.883333,-85.533333,0,129
109 | 107,Key Field,MEI,Meridian,32.333333,-88.75,0,96
110 | 108,Kingsley Field,LMT,Klamath Falls,42.166667,-121.733333,0,126
111 | 109,La Guardia,LGA,New York,40.766667,-73.866667,1,123
112 | 110,Lafayette Regional,LFT,"Lafayette, LA",30.205278,-91.9875,1,90
113 | 111,Lambert-St. Louis International,STL,St Louis,38.748611,-90.37,0,117
114 | 112,Lehigh Valley International,ABE,Allentown,40.652222,-75.440278,0,123
115 | 113,Lemons Municipal,TUP,Tupelo,34.268056,-88.77,0,102
116 | 114,Lincoln,LNK,"Lincoln, NE",40.850833,-96.759167,0,123
117 | 115,Logan International,BOS,Boston,42.363056,-71,0,126
118 | 116,Long Beach Municipal,LGB,Long Beach,33.816667,-118.15,1,102
119 | 117,Long Island Mac Arthur,ISP,"Islip, NY",40.795278,-73.100278,0,123
120 | 118,Los Angeles International,LAX,Los Angeles,33.9425,-118.407222,1,102
121 | 119,Louis Armstrong New Orléans International Airport,MSY,New Orleans,29.993333,-90.258056,1,90
122 | 120,Louisville International,SDF,"Louisville, KY",38.174444,-85.736111,0,114
123 | 121,Love Field,DAL,Dallas,32.852778,-96.85,0,99
124 | 122,Lovell Field,CHA,"Chattanooga,TN",35.035278,-85.203889,0,105
125 | 123,Manchester-boston Regional Airport,MHT,"Manchester, NH",42.9325,-71.435556,0,129
126 | 124,Mason City Municipal,MCW,"Mason City, IA",43.157778,-93.331389,0,129
127 | 125,MBS International,MBS,Saginaw,43.532778,-83.079722,0,132
128 | 126,Mc Allen Miller International,MFE,"Mc Allen, TX",26.175833,-98.238611,0,78
129 | 127,Mc Carran Intl,LAS,Las Vegas,36.083333,-115.166667,0,108
130 | 128,Mc Ghee Tyson,TYS,Knoxville,35.95,-83.916667,0,108
131 | 129,Melbourne International Airport,MLB,Melbourne,28.1,-80.633333,1,84
132 | 130,Memphis International,MEM,Memphis,35.066667,-89.966667,1,105
133 | 131,Metropolitan Airport,CAE,"Columbia, SC",33.95,-81.116667,0,102
134 | 132,Miami International Airport,MIA,Miami,25.783333,-80.266667,1,78
135 | 133,Mid-Continent,ICT,Wichita,37.65,-97.433333,0,114
136 | 134,Midway,MDW,Chicago,41.783333,-87.75,1,126
137 | 135,Mineta San Jose International Airport,SJC,San Jose,37.352778,-121.919444,1,111
138 | 136,Minneapolis - St. Paul Intl,MSP,Minneapolis,44.883333,-93.216944,1,135
139 | 137,Missoula International,MSO,Missoula,46.916667,-114.083333,0,141
140 | 138,Mobile Regional Airport,MOB,"Alabama, AL",30.691111,-88.242778,0,93
141 | 139,Monterey Peninsula,MRY,Monterey,36.583333,-121.85,0,111
142 | 140,Municipal,ABR,Aberdeen,45.45,-98.433333,0,135
143 | 141,Municipal,LSE,La Crosse,43.883333,-91.25,0,132
144 | 142,Municipal,LCH,Lake Charles,30.116667,-93.216667,0,90
145 | 143,Municipal,LWT,Lewistown,47.05,-109.466667,0,141
146 | 144,Municipal,MLS,Miles City,46.433333,-105.883333,0,138
147 | 145,Municipal,MLU,Monroe,32.5,-92.033333,0,99
148 | 146,Municipal,PSP,Palm Springs,33.833333,-116.5,0,102
149 | 147,Municipal,STC,Saint Cloud,45.583333,-94.183333,0,138
150 | 148,Municipal,SBA,"Santa Barbara, CA",33.426111,-119.840278,0,99
151 | 149,Municipal/Baer Field,FWA,Fort Wayne,41.116667,-85.116667,0,123
152 | 150,Muskegon,MKG,Muskegon,43.166667,-86.233333,0,129
153 | 151,Myrtle Beach Afb,MYR,Myrtle Beach,33.7,-78.966667,0,102
154 | 152,Nashville International,BNA,"Nashville, TN",36.124444,-86.678056,1,108
155 | 153,Natrona County International Airport,CPR,"Casper, WY",42.908056,-106.464444,0,129
156 | 154,Newark Liberty International,EWR,Newark,40.6925,-74.168611,0,123
157 | 155,Newport News/williamsb,PHF,Newport News,37.133333,-76.5,0,111
158 | 156,Nez Perce County Rgnl,LWS,Lewiston,46.383333,-117.033333,0,138
159 | 157,Norfolk International Airport,ORF,Norfolk,36.9,-76.2,0,111
160 | 158,North Bend,OTH,North Bend,43.416667,-124.25,0,129
161 | 159,Northwest Arkansas Regional,XNA,"Fayetteville, AR",36.281667,-94.306667,0,108
162 | 160,Oakland International Airport,OAK,Oakland,37.716667,-122.216667,0,114
163 | 161,Oneida County,RHI,Rhinelander,45.633333,-89.45,0,138
164 | 162,Ontario International,ONT,Ontario,34.056111,-117.601111,1,102
165 | 163,Orlando International,MCO,Orlando,28.429444,-81.308889,1,84
166 | 164,Outagamie County,ATW,Appleton,44.266667,-88.516667,0,132
167 | 165,Palm Beach International,PBI,West Palm Beach,26.683056,-80.095556,0,81
168 | 166,Pangborn Field,EAT,Wenatchee,47.4,-120.2,0,141
169 | 167,Pendleton,PDT,Pendleton,45.7,-118.833333,0,138
170 | 168,Philadelphia International,PHL,Philadelphia,39.871944,-75.241111,0,120
171 | 169,Piedmont Triad Intl,GSO,"Greensboro, NC",36.097778,-79.937222,1,108
172 | 170,Pierre,PIR,Pierre,44.383333,-100.283333,0,132
173 | 171,Pittsburgh International,PIT,"Pittsburgh, PA",40.491389,-80.232778,1,120
174 | 172,Port Columbus Intl,CMH,Columbus,40,-82.883333,1,120
175 | 173,Portland International,PDX,"Portland, OR",45.588611,-122.5975,0,138
176 | 174,Pullman-Moscow Regional Airport,PUW,Pullman,46.75,-117.116667,0,141
177 | 175,Quad-City,MLI,Moline,41.45,-90.516667,0,123
178 | 176,Raleigh-durham International Airport,RDU,"Raleigh/Durham, NC",35.877778,-78.7875,0,108
179 | 177,Redding,RDD,Redding,40.5,-122.3,0,123
180 | 178,Regional,DAB,Daytona Beach,29.183333,-81.05,0,87
181 | 179,Regional,FSM,Fort Smith,35.333333,-94.366667,0,105
182 | 180,Regional,PNS,Pensacola,30.466667,-87.183333,0,90
183 | 181,Regional,RAP,Rapid City,44.033333,-103.05,0,132
184 | 182,Regional,SHV,Shreveport,32.45,-93.816667,0,96
185 | 183,Reno-Tahoe International,RNO,"Reno, NV",39.499167,-119.768056,0,117
186 | 184,Richland Municipal,SDY,Sidney,47.716667,-104.183333,1,144
187 | 185,Richmond International Airport,RIC,"Richmond, VA",37.5,-77.316667,0,114
188 | 186,Roanoke Regional Airport,ROA,Roanoke,37.316667,-79.983333,0,111
189 | 187,Roberts Field,RDM,Redmond,44.25,-121.15,0,132
190 | 188,Rogue Valley International - Medford Airport,MFR,Medford,42.366667,-122.866667,0,126
191 | 189,Ronald Reagan Washington National Airport,DCA,"Washington, DC",38.851944,-77.037778,1,117
192 | 190,Ryan,BTR,Baton Rouge,30.533333,-91.15,0,93
193 | 191,Sacramento International,SMF,"Sacramento, CA",38.7,-121.616667,0,117
194 | 192,Salt Lake City International,SLC,"Salt Lake City, UT",40.788333,-111.966667,0,123
195 | 193,San Antonio International,SAT,San Antonio,29.533333,-98.466667,1,90
196 | 194,San Diego International Airport,SAN,San Diego,32.733333,-117.183333,1,99
197 | 195,San Francisco International,SFO,"San Francisco, CA",37.618889,-122.375,1,114
198 | 196,San Luis County Regional Airport,SBP,San Luis Obispo,35.236944,-120.641944,0,105
199 | 197,Sarasota-Bradenton International Airport,SRQ,"Sarasota, FL",27.395556,-82.554444,0,81
200 | 198,Savannah/Hilton Head,SAV,Savannah,32.133333,-81.2,1,96
201 | 199,Sawyer International,MQT,Marquette,46.533333,-87.566667,1,141
202 | 200,Seattle-Tacoma International,SEA,"Seattle, WA",47.448889,-122.309444,0,141
203 | 201,Sheffield,MSL,Sheffield,34.75,-87.616667,0,105
204 | 202,Sioux Gateway,SUX,Sioux City,42.4,-96.383333,0,126
205 | 203,Sky Harbor Intl,PHX,Phoenix,33.433333,-112.033333,1,99
206 | 204,South Bend Regional,SBN,South Bend,41.7,-86.316667,0,126
207 | 205,Southwest Florida Reg,RSW,Fort Myers,26.542222,-81.755278,0,81
208 | 206,Spokane International,GEG,Spokane,47.619722,-117.533889,0,144
209 | 207,Springfield-Branson Rg,SGF,Springfield,37.25,-93.383333,0,111
210 | 208,Stewart,SWF,Newburgh,41.5,-74.016667,0,126
211 | 209,Sun Valley,SUN,Sun Valley,43.5,-114.316667,0,132
212 | 210,Syracuse Hancock International Airport,SYR,Syracuse,43.116667,-76.116667,1,129
213 | 211,T. F. Green Airport,PVD,Providence,41.733333,-71.433333,0,126
214 | 212,Tallahassee Regional Airport,TLH,Tallahassee,30.396389,-84.350278,0,90
215 | 213,Tampa International,TPA,Tampa,27.975556,-82.533056,1,84
216 | 214,Toledo Express,TOL,"Toledo, OH",41.586944,-83.807778,0,126
217 | 215,Tompkins County,ITH,Ithaca,42.483333,-76.466667,1,126
218 | 216,Tri-cities,PSC,"Pasco, WA",46.264722,-119.119167,0,138
219 | 217,Tri-cities Regional,TRI,Blountville,36.475278,-82.4075,0,108
220 | 218,Tucson International Airport,TUS,"Tucson, AZ",32.116111,-110.941111,0,96
221 | 219,Tulsa International,TUL,Tulsa,36.198333,-95.888056,1,108
222 | 220,University Of Illinois Willard,CMI,Champaign,40.033333,-88.283333,0,120
223 | 221,University Park,SCE,State College,40.772222,-77.883333,0,123
224 | 222,Walla Walla,ALW,Walla Walla,46.1,-118.3,0,138
225 | 223,Washington Dulles International,IAD,"Washington, DC",38.944444,-77.455833,0,117
226 | 224,Waterloo,ALO,Waterloo,42.55,-92.383333,0,129
227 | 225,Watertown,ATY,Watertown,44.916667,-97.15,0,135
228 | 226,Westchester County Apt,HPN,White Plains,41.066667,-73.7,0,123
229 | 227,Westmoreland County,LBE,Latrobe,40.283333,-79.4,0,120
230 | 228,Wilkes-Barre/Scranton International Airport,AVP,"Wilkes-Barre/Scranton, PA",41.338333,-75.723333,0,123
231 | 229,Will Rogers World Airport,OKC,Oklahoma City,35.393056,-97.600833,0,105
232 | 230,William P Hobby,HOU,"Houston, TX",29.645556,-95.278889,1,90
233 | 231,Wilmington International,ILM,Wilmington,34.270556,-77.9025,0,102
234 | 232,Yakima Air Terminal,YKM,Yakima,46.566667,-120.533333,0,141
235 | 233,Yampa Valley,HDN,Hayden,40.519444,-106.869444,0,123
236 | 234,Yeager,CRW,Charleston,38.366667,-81.6,0,114
237 |
--------------------------------------------------------------------------------
/Data files/Images/news.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kateto/R-Network-Visualization-Basics-to-Advanced/bf96046325c76018b3e61b5777f0b276e3038e29/Data files/Images/news.png
--------------------------------------------------------------------------------
/Data files/Images/puppy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kateto/R-Network-Visualization-Basics-to-Advanced/bf96046325c76018b3e61b5777f0b276e3038e29/Data files/Images/puppy.png
--------------------------------------------------------------------------------
/Data files/Images/user.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kateto/R-Network-Visualization-Basics-to-Advanced/bf96046325c76018b3e61b5777f0b276e3038e29/Data files/Images/user.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # R-Network-Visualization-Basics-to-Advanced
2 |
3 | Basic and advanced network visualization with R
4 | (code and tutorial from my Sunbelt 2016 workshop)
5 |
6 | The tutorial covers network visualization using the R language for statistical computing (cran.r-project.org) and RStudio (rstudio.com). It provides a brief overview of network formats, focusing on their structure and representation in key R packages. The manual includes a step-by-step guide describing (through series of examples) the path from raw data to graph visualization in the igraph and Statnet frameworks. The advanced portion of this manual introduces dynamic visualization for longitudinal networks and combining networks with geographic maps.
7 |
--------------------------------------------------------------------------------
/Sunbelt 2016 R Network Visualization Handout.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kateto/R-Network-Visualization-Basics-to-Advanced/bf96046325c76018b3e61b5777f0b276e3038e29/Sunbelt 2016 R Network Visualization Handout.pdf
--------------------------------------------------------------------------------
/Sunbelt 2016 R Network Visualization Workshop.R:
--------------------------------------------------------------------------------
1 |
2 | ##========================================================##
3 | ## ##
4 | ## Basic and advanced network visualization with R ##
5 | ## Sunbelt 2016 Workshop, Newport Beach CA ##
6 | ## ##
7 | ## Katya Ognyanova, katya@ognyanova.net ##
8 | ## www.kateto.net/sunbelt2016 ##
9 | ## ##
10 | ##========================================================##
11 |
12 |
13 |
14 | # ================ Introduction ================
15 |
16 |
17 | # Download handouts and example data: bit.ly/sunbelt16-r
18 | # An online version of the tutorial will be available at
19 | # kateto.net/sunbelt2016
20 |
21 |
22 | # CONTENTS
23 | #
24 | # 1. R colors and fonts
25 | # 2. Reading in the network data
26 | # 3. Plotting networks with 'igraph'
27 | # 4. Plotting two-mode networks
28 | # 5. Quick example using 'network'
29 | # 6. Interactive D3 Networks
30 | # 7. Simple plot animations in R
31 | # 8. Interactive and dynamic networks with ndtv-d3
32 | # 9. Plotting networks on a geographic map
33 | #
34 |
35 |
36 | # LIBRARIES
37 | #
38 | # Key packages to install if you do not have the latest versions:
39 | # (do not load those yet!)
40 |
41 | install.packages("igraph")
42 | install.packages("network")
43 | install.packages("sna")
44 | install.packages("ndtv")
45 |
46 |
47 | # Optional packages that you might install if you
48 | # would like to run all of the examples below
49 | # (those are not critical and can be skipped)
50 |
51 | install.packages("RColorBrewer")
52 | install.packages("extrafont")
53 | install.packages("png")
54 | install.packages("networkD3")
55 | install.packages('animation')
56 | install.packages("ndtv", dependencies=T)
57 | install.packages("maps")
58 | install.packages("geosphere")
59 |
60 |
61 |
62 |
63 | # ================ 1. R colors and fonts ================
64 |
65 |
66 | # ------->> Colors in R plots --------
67 |
68 | # In most R functions, you can use named colors, hex, or rgb values:
69 | # (In the simple base plot chart below x and y are point coordinates, pch
70 | # is the point symbol shape, cex is the point size, and col is the color.
71 | # to see the parameters for plotting in base R, check out ?par
72 | plot(x=1:10, y=rep(5,10), pch=19, cex=5, col="dark red")
73 | points(x=1:10, y=rep(6, 10), pch=19, cex=5, col="#557799")
74 | points(x=1:10, y=rep(4, 10), pch=19, cex=5, col=rgb(.25, .5, .3))
75 |
76 | # You may notice that rgb here ranges from 0 to 1. While this is the R default,
77 | # you can also set it for the more typical 0-255 range:
78 | rgb(10, 100, 100, maxColorValue=255)
79 |
80 | # We can also set the opacity/transparency using the parameter 'alpha' (range 0-1):
81 | plot(x=1:5, y=rep(5,5), pch=19, cex=16, col=rgb(.25, .5, .3, alpha=.5), xlim=c(0,6))
82 |
83 | # If we have a hex color representation, we can set the transparency alpha
84 | # using 'adjustcolor' from package 'grDevices'. For fun, let's also set the
85 | # the plot background to black using the par() function for graphical parameters.
86 | # We could also set the margins in par() with mar=c(bottom, left, top, right).
87 | par(bg="black")
88 | col.tr <- grDevices::adjustcolor("#557799", alpha=0.7)
89 | plot(x=1:5, y=rep(5,5), pch=19, cex=20, col=col.tr, xlim=c(0,6))
90 | par(bg="white")
91 |
92 | # If you plan on using the built-in color names, here's what they are:
93 | colors() # all colors
94 | grep("blue", colors(), value=T) # colors that have 'blue' in the name
95 |
96 | # In many cases, we need a number of contrasting colors, or multiple shades of a color.
97 | # R comes with some predefined palette function that can generate those for us.
98 | pal1 <- heat.colors(5, alpha=1) # generate 5 colors from the heat palette, opaque
99 | pal2 <- rainbow(5, alpha=.5) # generate 5 colors from the heat palette, semi-transparent
100 | plot(x=1:10, y=1:10, pch=19, cex=10, col=pal1)
101 | par(new=TRUE) # tells R not to clear the first plot before adding the second one
102 | plot(x=10:1, y=1:10, pch=19, cex=10, col=pal2)
103 |
104 | # We can also generate our own gradients using colorRampPalette.
105 | # Note that colorRampPalette returns a *function* that we can use
106 | # to generate as many colors from that palette as we need.
107 |
108 | palf <- colorRampPalette(c("gray70", "dark red"))
109 | plot(x=10:1, y=1:10, pch=19, cex=10, col=palf(10))
110 |
111 | # To add transparency to colorRampPalette, you need to add a parameter `alpha=TRUE`:
112 | palf <- colorRampPalette(c(rgb(1,1,1, .2),rgb(.8,0,0, .7)), alpha=TRUE)
113 | plot(x=10:1, y=1:10, pch=19, cex=10, col=palf(10))
114 |
115 | # Finding good color combinations is a tough task - and the built-in R palettes
116 | # are rather limited. Thankfully there are other available packages for this:
117 |
118 | # install.packages("RColorBrewer")
119 | library(RColorBrewer)
120 |
121 | display.brewer.all()
122 |
123 | # This package has one main function, called 'brewer.pal'.
124 | # Using it, you just need to select the desired palette and a number of colors.
125 | # Let's take a look at some of the RColorBrewer palettes:
126 | display.brewer.pal(8, "Set3")
127 | display.brewer.pal(8, "Spectral")
128 | display.brewer.pal(8, "Blues")
129 |
130 |
131 | # Plot figures using ColorBrewer
132 | # We'll use par() to plot multiple figures.
133 | # plot row by row: mfrow=c(number of rows, number of columns)
134 | # plot column by column: mfcol=c(number of rows, number of columns)
135 |
136 | par(mfrow=c(1,2)) # plot two figures - 1 row, 2 columns
137 |
138 | pal3 <- brewer.pal(10, "Set3")
139 | plot(x=10:1, y=10:1, pch=19, cex=6, col=pal3)
140 | plot(x=10:1, y=10:1, pch=19, cex=6, col=rev(pal3)) # backwards
141 |
142 | dev.off() # shut off the graphic device to clear the two-figure configuration.
143 |
144 |
145 | detach(package:RColorBrewer)
146 |
147 |
148 |
149 | # ------->> Fonts in R plots --------
150 |
151 | # Using different fonts for R plots may take a little bit of work.
152 | # Especially for Windows - Mac & Linux users may not have to do this.
153 | # First we'd use the 'extrafont' package to import the fonts from the OS into R:
154 |
155 | # install.packages("extrafont")
156 |
157 | library(extrafont)
158 |
159 | # Import system fonts - may take a while, so DO NOT run this during the workshop.
160 | # font_import()
161 | fonts() # See what font families are available to you now.
162 | loadfonts(device = "win") # use device = "pdf" for pdf plot output.
163 |
164 | # Now you should be able to do this:
165 | plot(x=10:1, y=10:1, pch=19, cex=6, main="This is a plot",
166 | col="orange", family="Arial Black" )
167 |
168 | # To embed the fonts & use them in PDF files:
169 | # First you may have to let R know where to find ghostscript
170 | Sys.setenv(R_GSCMD = "C:/Program Files/gs/gs9.10/bin/gswin64c.exe")
171 |
172 | # The command 'pdf' will send all the plots we output before dev.off() to a pdf file:
173 | pdf(file="ArialBlack.pdf")
174 | plot(x=10:1, y=10:1, pch=19, cex=6, main="This is a plot",
175 | col="orange", family="Arial Black" )
176 | dev.off()
177 |
178 |
179 | embed_fonts("ArialBlack.pdf", outfile="ArialBlack_embed.pdf")
180 |
181 |
182 | detach(package:extrafont)
183 |
184 |
185 |
186 | # ================ 2. Reading in the network data ================
187 |
188 |
189 | # Download the archive with the data files from http://bit.ly/sunbelt16-r
190 |
191 | rm(list = ls()) # clear your workspace by removing all objects returned by ls()
192 |
193 | # Set the working directory to the folder containing the workshop files:
194 | setwd("C:/Data files")
195 |
196 |
197 |
198 | # DATASET 1: edgelist
199 |
200 | nodes <- read.csv("Dataset1-Media-Example-NODES.csv", header=T, as.is=T)
201 | links <- read.csv("Dataset1-Media-Example-EDGES.csv", header=T, as.is=T)
202 |
203 | # Examine the data:
204 | head(nodes)
205 | head(links)
206 | nrow(nodes); length(unique(nodes$id))
207 | nrow(links); nrow(unique(links[,c("from", "to")]))
208 |
209 | # Collapse multiple links of the same type between the same two nodes
210 | # by summing their weights, using aggregate() by "from", "to", & "type":
211 | links <- aggregate(links[,3], links[,-3], sum)
212 | links <- links[order(links$from, links$to),]
213 | colnames(links)[4] <- "weight"
214 | rownames(links) <- NULL
215 |
216 | nrow(links); nrow(unique(links[,c("from", "to")]))
217 |
218 |
219 | # DATASET 2: matrix
220 |
221 | nodes2 <- read.csv("Dataset2-Media-User-Example-NODES.csv", header=T, as.is=T)
222 | links2 <- read.csv("Dataset2-Media-User-Example-EDGES.csv", header=T, row.names=1)
223 |
224 | # Examine the data:
225 | head(nodes2)
226 | head(links2)
227 |
228 | # links2 is a matrix for a two-mode network:
229 | links2 <- as.matrix(links2)
230 | dim(links2)
231 | dim(nodes2)
232 |
233 |
234 | # ================ 3. Plotting networks with igraph ================
235 |
236 |
237 | # ------->> Turning networks into igraph objects --------
238 |
239 | library(igraph)
240 |
241 | # DATASET 1
242 |
243 | # Converting the data to an igraph object:
244 | # The graph_from_data_frame() function takes two data frames: 'd' and 'vertices'.
245 | # 'd' describes the edges of the network - it should start with two columns
246 | # containing the source and target node IDs for each network tie.
247 | # 'vertices' should start with a column of node IDs.
248 | # Any additional columns in either data frame are interpreted as attributes.
249 |
250 | net <- graph_from_data_frame(d=links, vertices=nodes, directed=T)
251 |
252 | # Examine the resulting object:
253 | class(net)
254 | net
255 |
256 | # We can look at the nodes, edges, and their attributes:
257 | E(net)
258 | V(net)
259 | E(net)$type
260 | V(net)$media
261 |
262 | # Or find specific nodes and edges by attribute:
263 | # (that returns objects of type vertex sequence / edge sequence)
264 | V(net)[media=="BBC"]
265 | E(net)[type=="mention"]
266 |
267 |
268 | # If you need them, you can extract an edge list
269 | # or a matrix back from the igraph networks.
270 | as_edgelist(net, names=T)
271 | as_adjacency_matrix(net, attr="weight")
272 |
273 | # Or data frames describing nodes and edges:
274 | as_data_frame(net, what="edges")
275 | as_data_frame(net, what="vertices")
276 |
277 |
278 | # You can also look at the network matrix directly:
279 | net[1,]
280 | net[5,7]
281 |
282 | # First attempt to plot the graph:
283 | plot(net) # not pretty!
284 |
285 | # Removing loops from the graph:
286 | net <- simplify(net, remove.multiple = F, remove.loops = T)
287 |
288 | # Let's and reduce the arrow size and remove the labels:
289 | plot(net, edge.arrow.size=.4,vertex.label=NA)
290 |
291 |
292 |
293 | # DATASET 2
294 |
295 |
296 | head(nodes2)
297 | head(links2)
298 |
299 | # Create a igraph network object from the two-mode matrix:
300 | net2 <- graph_from_incidence_matrix(links2)
301 |
302 | # A built-in vertex attribute 'type' shows which mode vertices belong to.
303 | table(V(net2)$type)
304 |
305 | plot(net2,vertex.label=NA)
306 |
307 | # To transform a one-mode network matrix into an igraph object,
308 | # we would use graph_from_adjacency_matrix()
309 |
310 |
311 |
312 | # ------->> Plotting parameters in igraph --------
313 |
314 | # Plotting with igraph: node options (starting with 'vertex.') and edge options
315 | # (starting with 'edge.'). A list of options is included in your handout.
316 | ?igraph.plotting
317 |
318 | # We can set the node & edge options in two ways - one is to specify
319 | # them in the plot() function, as we are doing below.
320 |
321 | # Plot with curved edges (edge.curved=.1) and reduce arrow size:
322 | # Note that using curved edges will allow you to see multiple links
323 | # between two nodes (e.g. links going in either direction, or multiplex links)
324 | plot(net, edge.arrow.size=.4, edge.curved=.1)
325 |
326 | # Set node color to orange and the border color to hex #555555
327 | # Replace the vertex label with the node names stored in "media"
328 | plot(net, edge.arrow.size=.4, edge.curved=0,
329 | vertex.color="orange", vertex.frame.color="#555555",
330 | vertex.label=V(net)$media, vertex.label.color="black",
331 | vertex.label.cex=.7)
332 |
333 |
334 | # The second way to set attributes is to add them to the igraph object.
335 |
336 | # Generate colors based on media type:
337 | colrs <- c("gray50", "tomato", "gold")
338 | V(net)$color <- colrs[V(net)$media.type]
339 |
340 | # Compute node degree (#links) and use it to set node size:
341 | deg <- degree(net, mode="all")
342 | V(net)$size <- deg*3
343 | V(net)$size <- V(net)$audience.size*0.6
344 |
345 | # The labels are currently node IDs.
346 | # Setting them to NA will render no labels:
347 | V(net)$label.color <- "black"
348 | V(net)$label <- NA
349 |
350 | # Set edge width based on weight:
351 | E(net)$width <- E(net)$weight/6
352 |
353 | #change arrow size and edge color:
354 | E(net)$arrow.size <- .2
355 | E(net)$edge.color <- "gray80"
356 |
357 | plot(net)
358 |
359 | # We can also override the attributes explicitly in the plot:
360 | plot(net, edge.color="orange", vertex.color="gray50")
361 |
362 |
363 | # We can also add a legend explaining the meaning of the colors we used:
364 | plot(net)
365 | legend(x=-1.1, y=-1.1, c("Newspaper","Television", "Online News"), pch=21,
366 | col="#777777", pt.bg=colrs, pt.cex=2.5, bty="n", ncol=1)
367 |
368 |
369 | # Sometimes, especially with semantic networks, we may be interested in
370 | # plotting only the labels of the nodes:
371 |
372 | plot(net, vertex.shape="none", vertex.label=V(net)$media,
373 | vertex.label.font=2, vertex.label.color="gray40",
374 | vertex.label.cex=1.2, edge.color="gray90")
375 |
376 |
377 | # Let's color the edges of the graph based on their source node color.
378 | # We'll get the starting node for each edge with "ends()".
379 | # It provides the start & end for each edge in 'es', and 'names' controls
380 | # whether ends() will return node names or IDs.
381 | edge.start <- ends(net, es=E(net), names=F)[,1]
382 | edge.col <- V(net)$color[edge.start]
383 |
384 | plot(net, edge.color=edge.col, edge.curved=.1)
385 |
386 |
387 |
388 | # ------->> Network Layouts --------
389 |
390 |
391 | # Network layouts are algorithms that return coordinates for each
392 | # node in a network.
393 |
394 | # Let's generate a slightly larger 80-node graph using
395 | # a preferential attachment model (Barabasi-Albert).
396 |
397 | net.bg <- sample_pa(80, 1.2)
398 | V(net.bg)$size <- 8
399 | V(net.bg)$frame.color <- "white"
400 | V(net.bg)$color <- "orange"
401 | V(net.bg)$label <- ""
402 | E(net.bg)$arrow.mode <- 0
403 | plot(net.bg)
404 |
405 | # Now let's plot this network using the layouts available in igraph
406 | # You can set the layout in the plot function:
407 | plot(net.bg, layout=layout_randomly)
408 |
409 | # Or calculate the vertex coordinates in advance:
410 | l <- layout_in_circle(net.bg)
411 | plot(net.bg, layout=l)
412 |
413 | # l is simply a matrix of x,y coordinates (N x 2) for the N nodes in the graph.
414 | # You can generate your own:
415 | l
416 | l <- cbind(1:vcount(net.bg), c(1, vcount(net.bg):2))
417 | plot(net.bg, layout=l)
418 |
419 | # This layout is just an example and not very helpful - thankfully
420 | # igraph has a number of built-in layouts, including:
421 |
422 | # Randomly placed vertices
423 | l <- layout_randomly(net.bg)
424 | plot(net.bg, layout=l)
425 |
426 | # Circle layout
427 | l <- layout_in_circle(net.bg)
428 | plot(net.bg, layout=l)
429 |
430 | # 3D sphere layout
431 | l <- layout_on_sphere(net.bg)
432 | plot(net.bg, layout=l)
433 |
434 | # The Fruchterman-Reingold force-directed algorithm
435 | # Nice but slow, most often used in graphs smaller than ~1000 vertices.
436 | l <- layout_with_fr(net.bg)
437 | plot(net.bg, layout=l)
438 |
439 | # You will also notice that the F-R layout is not deterministic - different
440 | # runs will result in slightly different configurations. Saving the layout
441 | # in l allows us to get the exact same result multiple times.
442 | par(mfrow=c(2,2), mar=c(1,1,1,1))
443 | plot(net.bg, layout=layout_with_fr)
444 | plot(net.bg, layout=layout_with_fr)
445 | plot(net.bg, layout=l)
446 | plot(net.bg, layout=l)
447 | dev.off()
448 |
449 | # By default, the coordinates of the plots are rescaled to the [-1,1] interval
450 | # for both x and y. You can change that with the parameter "rescale=FALSE"
451 | # and rescale your plot manually by multiplying the coordinates by a scalar.
452 | # You can use norm_coords to normalize the plot with the boundaries you want.
453 | # This way you can create more compact or spread out layout versions.
454 |
455 | # Get the layout coordinates:
456 | l <- layout_with_fr(net.bg)
457 | # Normalize them so that they are in the -1, 1 interval:
458 | l <- norm_coords(l, ymin=-1, ymax=1, xmin=-1, xmax=1)
459 |
460 | par(mfrow=c(2,2), mar=c(0,0,0,0))
461 | plot(net.bg, rescale=F, layout=l*0.4)
462 | plot(net.bg, rescale=F, layout=l*0.8)
463 | plot(net.bg, rescale=F, layout=l*1.2)
464 | plot(net.bg, rescale=F, layout=l*1.6)
465 | dev.off()
466 |
467 | # Another popular force-directed algorithm that produces nice results for
468 | # connected graphs is Kamada Kawai. Like Fruchterman Reingold, it attempts to
469 | # minimize the energy in a spring system.
470 |
471 | l <- layout_with_kk(net.bg)
472 | plot(net.bg, layout=l)
473 |
474 | # The LGL algorithm is for large connected graphs. Here you can specify a root -
475 | # the node that will be placed in the middle of the layout.
476 | plot(net.bg, layout=layout_with_lgl)
477 |
478 | # By default, igraph uses a layout called layout_nicely which selects
479 | # an appropriate layout algorithm based on the properties of the graph.
480 |
481 | # Check out all available layouts in igraph:
482 | ?igraph::layout_
483 |
484 | layouts <- grep("^layout_", ls("package:igraph"), value=TRUE)[-1]
485 | # Remove layouts that do not apply to our graph.
486 | layouts <- layouts[!grepl("bipartite|merge|norm|sugiyama|tree", layouts)]
487 |
488 | par(mfrow=c(3,3), mar=c(1,1,1,1))
489 |
490 | for (layout in layouts) {
491 | print(layout)
492 | l <- do.call(layout, list(net))
493 | plot(net, edge.arrow.mode=0, layout=l, main=layout) }
494 |
495 | dev.off()
496 |
497 |
498 |
499 | # ------->> Highlighting aspects of the network --------
500 |
501 |
502 | plot(net)
503 |
504 | # Notice that this network plot is still not too helpful.
505 | # We can identify the type and size of nodes, but cannot see
506 | # much about the structure since the links we're examining are so dense.
507 | # One way to approach this is to see if we can sparsify the network.
508 |
509 | hist(links$weight)
510 | mean(links$weight)
511 | sd(links$weight)
512 |
513 | # There are more sophisticated ways to extract the key edges,
514 | # but for the purposes of this exercise we'll only keep ones
515 | # that have weight higher than the mean for the network.
516 |
517 | # We can delete edges using delete_edges(net, edges)
518 | # (or, by the way, add edges with add_edges(net, edges) )
519 | cut.off <- mean(links$weight)
520 | net.sp <- delete_edges(net, E(net)[weight> Highlighting specific nodes or links --------
573 |
574 |
575 | # Sometimes we want to focus the visualization on a particular node
576 | # or a group of nodes. Let's represent distance from the NYT:
577 | dist.from.NYT <- distances(net, v=V(net)[media=="NY Times"], to=V(net), weights=NA)
578 |
579 | # Set colors to plot the distances:
580 | oranges <- colorRampPalette(c("dark red", "gold"))
581 | col <- oranges(max(dist.from.NYT)+1)
582 | col <- col[dist.from.NYT+1]
583 |
584 | plot(net, vertex.color=col, vertex.label=dist.from.NYT, edge.arrow.size=.6,
585 | vertex.label.color="white")
586 |
587 |
588 | # We can also highlight paths between the nodes in the network.
589 | # Say here between MSNBC and the New York Post:
590 | news.path <- shortest_paths(net,
591 | from = V(net)[media=="MSNBC"],
592 | to = V(net)[media=="New York Post"],
593 | output = "both") # both path nodes and edges
594 |
595 | # Generate edge color variable to plot the path:
596 | ecol <- rep("gray80", ecount(net))
597 | ecol[unlist(news.path$epath)] <- "orange"
598 | # Generate edge width variable to plot the path:
599 | ew <- rep(2, ecount(net))
600 | ew[unlist(news.path$epath)] <- 4
601 | # Generate node color variable to plot the path:
602 | vcol <- rep("gray40", vcount(net))
603 | vcol[unlist(news.path$vpath)] <- "gold"
604 |
605 | plot(net, vertex.color=vcol, edge.color=ecol,
606 | edge.width=ew, edge.arrow.mode=0)
607 |
608 |
609 | # Highlight the edges going into or out of a vertex, for instance the WSJ.
610 | # For a single node, use 'incident()', for multiple nodes use 'incident_edges()'
611 | inc.edges <- incident(net, V(net)[media=="Wall Street Journal"], mode="all")
612 |
613 | # Set colors to plot the selected edges.
614 | ecol <- rep("gray80", ecount(net))
615 | ecol[inc.edges] <- "orange"
616 | vcol <- rep("grey40", vcount(net))
617 | vcol[V(net)$media=="Wall Street Journal"] <- "gold"
618 | plot(net, vertex.color=vcol, edge.color=ecol)
619 |
620 |
621 | # Or we can highlight the immediate neighbors of a vertex, say WSJ.
622 | # The 'neighbors' function finds all nodes one step out from the focal actor.
623 | # To find the neighbors for multiple nodes, use 'adjacent_vertices()'.
624 | # To find node neighborhoods going more than one step out, use function 'ego()'
625 | # with parameter 'order' set to the number of steps out to go from the focal node(s).
626 |
627 | neigh.nodes <- neighbors(net, V(net)[media=="Wall Street Journal"], mode="out")
628 |
629 | # Set colors to plot the neighbors:
630 | vcol[neigh.nodes] <- "#ff9d00"
631 | plot(net, vertex.color=vcol)
632 |
633 |
634 | # Another way to draw attention to a group of nodes:
635 | plot(net, mark.groups=c(1,4,5,8), mark.col="#C5E5E7", mark.border=NA)
636 | # Mark multiple groups:
637 | plot(net, mark.groups=list(c(1,4,5,8), c(15:17)),
638 | mark.col=c("#C5E5E7","#ECD89A"), mark.border=NA)
639 |
640 |
641 |
642 | # ------->> Interactive plotting with tkplot --------
643 |
644 | # R and igraph offer interactive plotting capabilities
645 | # (mostly helpful for small networks)
646 |
647 | tkid <- tkplot(net) #tkid is the id of the tkplot
648 | l <- tkplot.getcoords(tkid) # grab the coordinates from tkplot
649 | plot(net, layout=l)
650 |
651 |
652 |
653 | # ------->> Other ways to represent a network --------
654 |
655 | # One reminder that there are other ways to represent a network:
656 |
657 | # Heatmap of the network matrix:
658 | netm <- get.adjacency(net, attr="weight", sparse=F)
659 | colnames(netm) <- V(net)$media
660 | rownames(netm) <- V(net)$media
661 |
662 | palf <- colorRampPalette(c("gold", "dark orange"))
663 |
664 | # The Rowv & Colv parameters turn dendrograms on and off
665 | heatmap(netm[,17:1], Rowv = NA, Colv = NA, col = palf(20),
666 | scale="none", margins=c(10,10) )
667 |
668 | # Degree distribution
669 | deg.dist <- degree_distribution(net, cumulative=T, mode="all")
670 | plot( x=0:max(deg), y=1-deg.dist, pch=19, cex=1.2, col="orange",
671 | xlab="Degree", ylab="Cumulative Frequency")
672 |
673 |
674 |
675 | # ================ 4. Plotting two-mode networks ================
676 |
677 |
678 | head(nodes2)
679 | head(links2)
680 |
681 | net2
682 | plot(net2)
683 |
684 | # This time we will make nodes look different based on their type.
685 | # Media outlets are blue squares, audience nodes are orange circles:
686 | V(net2)$color <- c("steel blue", "orange")[V(net2)$type+1]
687 | V(net2)$shape <- c("square", "circle")[V(net2)$type+1]
688 | # Media outlets will have name labels, audience members will not:
689 | V(net2)$label <- ""
690 | V(net2)$label[V(net2)$type==F] <- nodes2$media[V(net2)$type==F]
691 | V(net2)$label.cex=.6
692 | V(net2)$label.font=2
693 |
694 | plot(net2, vertex.label.color="white", vertex.size=(2-V(net2)$type)*8)
695 |
696 | # igraph has a built-in bipartite layoyt, though it's not the most helpful:
697 | plot(net2, vertex.label=NA, vertex.size=7, layout=layout_as_bipartite)
698 |
699 |
700 | # Using text as nodes:
701 | par(mar=c(0,0,0,0))
702 | plot(net2, vertex.shape="none", vertex.label=nodes2$media,
703 | vertex.label.color=V(net2)$color, vertex.label.font=2,
704 | vertex.label.cex=.95, edge.color="gray70", edge.width=2)
705 |
706 | dev.off()
707 |
708 |
709 | # Using images as nodes
710 | # You will need the 'png' library to do this:
711 |
712 | # install.packages("png")
713 | library("png")
714 |
715 | img.1 <- readPNG("./images/news.png")
716 | img.2 <- readPNG("./images/user.png")
717 |
718 | V(net2)$raster <- list(img.1, img.2)[V(net2)$type+1]
719 |
720 | par(mar=c(3,3,3,3))
721 |
722 | plot(net2, vertex.shape="raster", vertex.label=NA,
723 | vertex.size=16, vertex.size2=16, edge.width=2)
724 |
725 | # By the way, you can also add any image you want to any plot.
726 | # For example, many network graphs could be improved by a photo
727 | # of a puppy carrying a basket full of kittens.
728 | img.3 <- readPNG("./images/puppy.png")
729 | rasterImage(img.3, xleft=-1.7, xright=0, ybottom=-1.2, ytop=0)
730 |
731 |
732 | # The numbers after the image are coordinates for the plot.
733 | # The limits of your plotting area are given in par()$usr
734 |
735 | dev.off()
736 |
737 | detach(package:png)
738 |
739 | # We can also generate and plot bipartite projections for the two-mode network:
740 | # (co-memberships are easy to calculate by multiplying the network matrix by
741 | # its transposed matrix, or using igraph's bipartite.projection function)
742 |
743 | net2.bp <- bipartite.projection(net2)
744 |
745 | # We can calculate the projections manually as well:
746 | # as_incidence_matrix(net2) %*% t(as_incidence_matrix(net2))
747 | # t(as_incidence_matrix(net2)) %*% as_incidence_matrix(net2)
748 |
749 | par(mfrow=c(1,2))
750 |
751 | plot(net2.bp$proj1, vertex.label.color="black", vertex.label.dist=1,
752 | vertex.label=nodes2$media[!is.na(nodes2$media.type)])
753 |
754 | plot(net2.bp$proj2, vertex.label.color="black", vertex.label.dist=1,
755 | vertex.label=nodes2$media[ is.na(nodes2$media.type)])
756 |
757 | dev.off()
758 |
759 | # PSA: Remember to detach packages when you are done with them!
760 | # You may run into problems if you have igraph and Statnet packages loaded together.
761 | detach(package:igraph)
762 |
763 |
764 |
765 | # ================ 5. Quick example using the 'network' package ================
766 |
767 | # Plotting with the 'network' package is very similar to that with igraph -
768 | # although the notation is slightly different (a whole new set of parameter names!)
769 | # Here is a quick example using the (by now familiar) media network.
770 |
771 | #Just in case we have forgotten this earlier:
772 | dev.off()
773 | detach(package:igraph)
774 |
775 | # Load our main library:
776 | library(network)
777 |
778 | # What did our data look like?
779 | head(links)
780 | head(nodes)
781 |
782 | # Convert the data into the network format used by the Statnet family.
783 | # As in igraph, we can generate a 'network' object from an edgelist,
784 | # an adjacency matrix, or an incidence matrix.
785 | ?edgeset.constructors
786 |
787 | # Remember to set the ignore.eval to F for weighted networks.
788 | net3 <- network(links, vertex.attr=nodes, matrix.type="edgelist",
789 | loops=F, multiple=F, ignore.eval = F)
790 | net3
791 |
792 | # You can access the edges, vertices, and the network matrix using:
793 | net3[,]
794 | net3 %n% "net.name" <- "Media Network" # network attribute
795 | net3 %v% "media" # Node attribute
796 | net3 %e% "type" # Node attribute
797 |
798 | net3 %v% "col" <- c("gray70", "tomato", "gold")[net3 %v% "media.type"]
799 |
800 | # plot the network:
801 | plot(net3, vertex.cex=(net3 %v% "audience.size")/7, vertex.col="col")
802 |
803 | # For a full list of parameters that you can use in this plot,
804 | # check out ?plot.network.
805 | ?plot.network
806 |
807 | # Note that - as in igraph - the plot returns the node position coordinates.
808 | l <- plot(net3, vertex.cex=(net3 %v% "audience.size")/7, vertex.col="col")
809 | plot(net3, vertex.cex=(net3 %v% "audience.size")/7, vertex.col="col", coord=l)
810 |
811 |
812 | # The network package also offers the option to edit a plot interactively,
813 | # by setting the parameter interactive=T
814 |
815 | plot(net3, vertex.cex=(net3 %v% "audience.size")/7, vertex.col="col", interactive=T)
816 |
817 |
818 | detach(package:network)
819 |
820 | # ================ 6. Interactive D3 Networks ================
821 |
822 | # There are a number of libraries like rcharts and htmlwidgets that can
823 | # help you export interactive web charts from R. We'll take a quick look
824 | # at networkD3 which exports networks from r to javascript.
825 |
826 | # install.packages("networkD3")
827 |
828 | library(networkD3)
829 |
830 | # d3ForceNetwork expects node IDs that are numeric and start from 0
831 | # so we have to transform our character node IDs:
832 |
833 | el <- data.frame(from=as.numeric(factor(links$from))-1,
834 | to=as.numeric(factor(links$to))-1 )
835 |
836 | # The nodes need to be in the same order as the "source" column in links:
837 | nl <- cbind(idn=factor(nodes$media, levels=nodes$media), nodes)
838 |
839 | # The `Group` parameter is used to color the nodes.
840 | # Nodesize is not (as you might think) the size of the node, but the
841 | # number of the column in the node data that should be used for sizing.
842 | # The `charge` parameter guides node repulsion (if negative) or
843 | # attraction (if positive).
844 |
845 | forceNetwork(Links = el, Nodes = nl, Source="from", Target="to",
846 | NodeID = "idn", Group = "type.label",linkWidth = 1,
847 | linkColour = "#afafaf", fontSize=12, zoom=T, legend=T,
848 | Nodesize=6, opacity = 1, charge=-600,
849 | width = 600, height = 600)
850 |
851 |
852 | detach(package: networkD3)
853 |
854 | # ================ 7. Simple plot animations in R ================
855 |
856 | # If you have already installed "ndtv", you should also have
857 | # a package used by it called "animation".
858 |
859 | # install.packages('animation')
860 | library(animation)
861 | library(igraph)
862 |
863 | # In order for this to work, you need not only the R package,
864 | # but also an additional software called ImageMagick from imagemagick.org
865 |
866 | ani.options("convert") # Check that the package knows where to find ImageMagick
867 | ani.options(convert="C:/Program Files/ImageMagick-6.8.8-Q16/convert.exe")
868 |
869 | # You can use this technique to create various (not necessarily network-related)
870 | # animations in R by generating multiple plots and combining them in an animated GIF.
871 |
872 | l <- layout_with_fr(net)
873 |
874 | saveGIF( { col <- rep("grey40", vcount(net))
875 | plot(net, vertex.color=col, layout=l)
876 |
877 | step.1 <- V(net)[media=="Wall Street Journal"]
878 | col[step.1] <- "#ff5100"
879 | plot(net, vertex.color=col, layout=l)
880 |
881 | step.2 <- unlist(neighborhood(net, 1, step.1, mode="out"))
882 | col[setdiff(step.2, step.1)] <- "#ff9d00"
883 | plot(net, vertex.color=col, layout=l)
884 |
885 | step.3 <- unlist(neighborhood(net, 2, step.1, mode="out"))
886 | col[setdiff(step.3, step.2)] <- "#FFDD1F"
887 | plot(net, vertex.color=col, layout=l) },
888 | interval = .8, movie.name="network_animation.gif" )
889 |
890 | detach(package:igraph)
891 | detach(package:animation)
892 |
893 |
894 |
895 | # ================ 8. Interactive and dynamic networks with ndtv-d3 ================
896 |
897 |
898 |
899 | # ------->> Interactive network plots --------
900 |
901 |
902 | # install.packages("ndtv", dependencies=T)
903 |
904 | library(ndtv)
905 |
906 | # You should not need additional software to produce web animations with D3 (below).
907 | # If you want to save the animations as video files ( see ?saveVideo), you
908 | # would have to install a video converter called FFmpeg (http://ffmpg.org)
909 | # To find out how to get the right installation for your OS, check out ?install.ffmpeg
910 | # To use all available layouts, you would need to have Java installed on your machine.
911 |
912 |
913 | # Remember net3, our original media network turned into a 'network' object:
914 | net3
915 |
916 | # You will recognize a lot of the plotting parameters from 'network':
917 | # Two new parameters set the tooltips (the labels you see when you
918 | # click on network elements) - note that those take html.
919 |
920 | render.d3movie(net3, usearrows = F, displaylabels = F, bg="#111111",
921 | vertex.border="#ffffff", vertex.col = net3 %v% "col",
922 | vertex.cex = (net3 %v% "audience.size")/8,
923 | edge.lwd = (net3 %e% "weight")/3, edge.col = '#55555599',
924 | vertex.tooltip = paste("Name:", (net3 %v% 'media') , "
",
925 | "Type:", (net3 %v% 'type.label')),
926 | edge.tooltip = paste("Edge type:", (net3 %e% 'type'), "
",
927 | "Edge weight:", (net3 %e% "weight" ) ),
928 | launchBrowser=T, filename="Media-Network.html" )
929 |
930 |
931 | # If you are going to embed this in a markdown document,
932 | # you would also need to use output.mode='inline' above.
933 |
934 |
935 | # ------->> # Network evolution animations --------
936 |
937 |
938 | # In order to work with the network animations in ndtv, we need to understand the
939 | # dynamic network format used by Statnet packages, implemented in networkDynamic
940 |
941 | # Let's look at one of the example datasets included in the package:
942 | data(short.stergm.sim)
943 | short.stergm.sim
944 | head(as.data.frame(short.stergm.sim))
945 |
946 | # Plot the network ignoring time (all nodes & edges that were ever present):
947 | plot(short.stergm.sim)
948 |
949 | # Plot the network at time 1
950 | plot( network.extract(short.stergm.sim, at=1) )
951 |
952 | # Plot nodes & vertices that were active from time 1 to time 5:
953 | plot( network.extract(short.stergm.sim, onset=1, terminus=5, rule="all") )
954 |
955 | # Plot all nodes and vertices that were active between time 1 & 10:
956 | plot( network.extract(short.stergm.sim, onset=1, terminus=10, rule="any") )
957 |
958 | # Let's make a quick d3 animation from the example network:
959 | render.d3movie(short.stergm.sim,displaylabels=TRUE)
960 |
961 | # We are now ready to create and animate our own dynamic network.
962 |
963 | # Dynamic network object can be generated in a number of ways: from
964 | # a set of networks/matrices representing different time points, or from
965 | # data frames/matrices with node lists and edge lists indicating when each
966 | # is active, or when they switch state. See ?networkDynamic for more information.
967 |
968 | net3
969 | plot(net3)
970 |
971 | vs <- data.frame(onset=0, terminus=50, vertex.id=1:17)
972 | es <- data.frame(onset=1:49, terminus=50,
973 | head=as.matrix(net3, matrix.type="edgelist")[,1],
974 | tail=as.matrix(net3, matrix.type="edgelist")[,2])
975 |
976 | net3.dyn <- networkDynamic(base.net=net3, edge.spells=es, vertex.spells=vs)
977 |
978 |
979 | # Plot the network (all elements present at any time point):
980 | plot(net3.dyn, vertex.cex=(net3 %v% "audience.size")/7, vertex.col="col")
981 |
982 |
983 | # Plot the network as it looks during different time windows or at different time points.
984 |
985 | # We can pre-compute the animation coordinates (otherwise they get calculated when
986 | # you generate the animation). Here animation.mode is the layout algorithm -
987 | # one of "kamadakawai", "MDSJ", "Graphviz"and "useAttribute" (user-generated).
988 | # 'interval' is the time between layouts, 'aggregate.dur' is the time shown
989 | # in each layout, 'rule' is the rule for displaying elements (e.g. 'any': active
990 | # any time during that period, 'all' active the entire period, etc.
991 |
992 | compute.animation(net3.dyn, animation.mode = "kamadakawai",
993 | slice.par=list(start=0, end=49, interval=10,
994 | aggregate.dur=10, rule='any'))
995 |
996 | # Show time evolution through static images at different time points:
997 | filmstrip(net3.dyn, displaylabels=F, mfrow=c(2, 3),
998 | slice.par=list(start=0, end=49, interval=10,
999 | aggregate.dur=10, rule='any'))
1000 |
1001 | # Let's make an actial animation:
1002 |
1003 | compute.animation(net3.dyn, animation.mode = "kamadakawai",
1004 | slice.par=list(start=0, end=50, interval=1,
1005 | aggregate.dur=1, rule='any'))
1006 |
1007 |
1008 | render.d3movie(net3.dyn, usearrows = F,
1009 | displaylabels = F, label=net3 %v% "media",
1010 | bg="#ffffff", vertex.border="#333333",
1011 | vertex.cex = degree(net3)/2,
1012 | vertex.col = net3.dyn %v% "col",
1013 | edge.lwd = (net3.dyn %e% "weight")/3,
1014 | edge.col = '#55555599',
1015 | vertex.tooltip = paste("Name:", (net3.dyn %v% "media") , "
",
1016 | "Type:", (net3.dyn %v% "type.label")),
1017 | edge.tooltip = paste("Edge type:", (net3.dyn %e% "type"), "
",
1018 | "Edge weight:", (net3.dyn %e% "weight" ) ),
1019 | launchBrowser=T, filename="Media-Network-Dynamic.html",
1020 | render.par=list(tween.frames = 30, show.time = F),
1021 | plot.par=list(mar=c(0,0,0,0)) )
1022 |
1023 |
1024 | # In addition to dynamic nodes and edges, ndtv takes dynamic attributes.
1025 | # We could have added those to the es and vs data frames above.
1026 | # In addition, the plotting function can evaluate special parameters
1027 | # and generate dynamic arguments on the fly. For example,
1028 | # function(slice) { do some calculations with slice } will perform operations
1029 | # on the current time slice, allowing us to change parameters dynamically.
1030 | # See the node size below:
1031 |
1032 | compute.animation(net3.dyn, animation.mode = "kamadakawai",
1033 | slice.par=list(start=0, end=50, interval=4,
1034 | aggregate.dur=1, rule='any'))
1035 |
1036 |
1037 | render.d3movie(net3.dyn, usearrows = F,
1038 | displaylabels = F, label=net3 %v% "media",
1039 | bg="#000000", vertex.border="#dddddd",
1040 | vertex.cex = function(slice){ degree(slice)/2.5 },
1041 | vertex.col = net3.dyn %v% "col",
1042 | edge.lwd = (net3.dyn %e% "weight")/3,
1043 | edge.col = '#55555599',
1044 | vertex.tooltip = paste("Name:", (net3.dyn %v% "media") , "
",
1045 | "Type:", (net3.dyn %v% "type.label")),
1046 | edge.tooltip = paste("Edge type:", (net3.dyn %e% "type"), "
",
1047 | "Edge weight:", (net3.dyn %e% "weight" ) ),
1048 | launchBrowser=T, filename="Media-Network-even-more-Dynamic.html",
1049 | render.par=list(tween.frames = 25, show.time = F) )
1050 |
1051 |
1052 |
1053 |
1054 | # ================ 9. Plotting networks on a geographic map ================
1055 |
1056 | # The example below plots a network on a map using base R and mapping libraries.
1057 | # Note that for those familiar with it, the package 'ggplot2' may provide
1058 | # a more flexible way of doing this. Things there work similarly to below,
1059 | # but you would use borders() to plot the map and geom_path() for the edges.
1060 |
1061 |
1062 | rm(list = ls()) # clear the workspace
1063 |
1064 | # In order to plot on maps, we'll need two additional packages:
1065 | # 'maps' will help us generate a geographic map to use as a background
1066 | # 'geosphere' will help us create arcs representing the network edges
1067 |
1068 | # If you do not already have them, install the following packages:
1069 | # install.packages("maps")
1070 | # install.packages("geosphere")
1071 |
1072 | library(maps)
1073 | library(geosphere)
1074 |
1075 | # Library 'maps' has built-in maps it can plot for you. For example:
1076 | par(mfrow = c(2,2))
1077 |
1078 | map("usa", col="tomato", border="gray10", fill=TRUE, bg="gray30")
1079 | map("state", col="orange", border="gray10", fill=TRUE, bg="gray30")
1080 | map("county", col="palegreen", border="gray10", fill=TRUE, bg="gray30")
1081 | map("world", col="skyblue", border="gray10", fill=TRUE, bg="gray30")
1082 |
1083 | dev.off()
1084 |
1085 | # The data we will use contains US airports and flights among them.
1086 | # The airport file includes info about latitude and longitude.
1087 | # If we did not have those, we could use geocode() from `ggmap'
1088 | # to get latitude and longitude for an address.
1089 |
1090 | airports <- read.csv("Dataset3-Airlines-NODES.csv", header=TRUE)
1091 | flights <- read.csv("Dataset3-Airlines-EDGES.csv", header=TRUE, as.is=TRUE)
1092 |
1093 | head(flights)
1094 | head(airports)
1095 |
1096 | # Select only large airports: ones with more than 10 connections in the data.
1097 | tab <- table(flights$Source)
1098 | big.id <- names(tab)[tab>10]
1099 | airports <- airports[airports$ID %in% big.id,]
1100 | flights <- flights[flights$Source %in% big.id &
1101 | flights$Target %in% big.id, ]
1102 |
1103 |
1104 | # Plot a map of the united states:
1105 | map("state", col="grey20", fill=TRUE, bg="black", lwd=0.1)
1106 |
1107 | # Add a point on the map for each airport:
1108 | points(x=airports$longitude, y=airports$latitude, pch=19,
1109 | cex=airports$Visits/80, col="orange")
1110 |
1111 | # Generate edge colors: lighter color means higher flight volume.
1112 | col.1 <- adjustcolor("orange red", alpha=0.4)
1113 | col.2 <- adjustcolor("orange", alpha=0.4)
1114 | edge.pal <- colorRampPalette(c(col.1, col.2), alpha = TRUE)
1115 | edge.col <- edge.pal(100)
1116 |
1117 | # For each flight, we will generate the coordinates of an arc that connects
1118 | # its star and end point, using gcIntermediate() from package 'geosphere'.
1119 | # Then we will plot that arc over the map using lines().
1120 | for(i in 1:nrow(flights)) {
1121 | node1 <- airports[airports$ID == flights[i,]$Source,]
1122 | node2 <- airports[airports$ID == flights[i,]$Target,]
1123 |
1124 | arc <- gcIntermediate( c(node1[1,]$longitude, node1[1,]$latitude),
1125 | c(node2[1,]$longitude, node2[1,]$latitude),
1126 | n=1000, addStartEnd=TRUE )
1127 | edge.ind <- round(100*flights[i,]$Freq / max(flights$Freq))
1128 |
1129 | lines(arc, col=edge.col[edge.ind], lwd=edge.ind/30)
1130 | }
1131 |
1132 |
1133 |
1134 | # ================ |-------------| ================
1135 |
1136 |
1137 |
1138 |
1139 |
--------------------------------------------------------------------------------