network analytics
seetharam annepu
18 July 2018
ifelse(require(igraph),{library("igraph")},install.packages("igraph"))
## Loading required package: igraph
##
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
##
## decompose, spectrum
## The following object is masked from 'package:base':
##
## union
## [1] "igraph"
ifelse(require(igraphdata),{library("igraphdata")},install.packages("igraphdata"))
## Loading required package: igraphdata
## Warning: package 'igraphdata' was built under R version 3.5.3
## [1] "igraphdata"
ifelse(require(dplyr),{library("dplyr")},install.packages("dplyr"))
## Loading required package: dplyr
## Warning: package 'dplyr' was built under R version 3.5.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:igraph':
##
## as_data_frame, groups, union
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
## [1] "dplyr"
ifelse(require(tidyr),{library("tidyr")},install.packages("tidyr"))
## Loading required package: tidyr
##
## Attaching package: 'tidyr'
## The following object is masked from 'package:igraph':
##
## crossing
## [1] "tidyr"
ifelse(require(tmaptools),{library("tmaptools")},install.packages("tmaptools"))
## Loading required package: tmaptools
## Warning: package 'tmaptools' was built under R version 3.5.3
## [1] "tmaptools"
ifelse(require(rworldmap),{library("rworldmap")},install.packages("rworldmap"))
## Loading required package: rworldmap
## Warning: package 'rworldmap' was built under R version 3.5.3
## Loading required package: sp
## Warning: package 'sp' was built under R version 3.5.3
## ### Welcome to rworldmap ###
## For a short introduction type : vignette('rworldmap')
## [1] "rworldmap"
ifelse(require(devtools),{library("devtools")},install.packages("devtools"))
## Loading required package: devtools
## Warning: package 'devtools' was built under R version 3.5.3
## Warning: package 'usethis' was built under R version 3.5.3
## [1] "usethis"
ifelse(require(lubridate),{library("lubridate")},install.packages("lubridat"))
## Loading required package: lubridate
##
## Attaching package: 'lubridate'
## The following object is masked from 'package:igraph':
##
## %--%
## The following object is masked from 'package:base':
##
## date
## [1] "lubridate"
ifelse(require(doBy),{library("doBy")},install.packages("doBy"))
## Loading required package: doBy
## Warning: package 'doBy' was built under R version 3.5.3
## [1] "doBy"
#devtools::install_github("gsk3/taRifx.geo")
library("ggmap")
## Warning: package 'ggmap' was built under R version 3.5.3
## Loading required package: ggplot2
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
For this analysis, Divvy data is being used. although i initially did this analysis on flight data, I now wanted to try the analysis on bike sharing data from divvy to learn insights from a different context.
trips<-read.csv(file.choose(),header = T)
trips$start_time<-as.POSIXct(trips$start_time, format="%Y-%m-%d %H:%M:%S")
trips$end_time<-as.POSIXct(trips$end_time, format="%Y-%m-%d %H:%M:%S")
# trips %>%
# separate(start_time, c("start_date", "start_time"), " ")->trips
# trips %>%
# separate(start_time, c("end_date", "end_time"), " ")->trips
trips<-trips[months(trips$start_time) %in% month.name[10],]
#connections<-read.csv(file.choose(),header = T)
head(trips)
## trip_id start_time end_time bikeid tripduration
## 1 20983530 2018-10-01 00:01:17 2018-10-01 00:29:35 4551 1,698.0
## 2 20983531 2018-10-01 00:03:59 2018-10-01 00:10:55 847 416.0
## 3 20983532 2018-10-01 00:05:14 2018-10-01 00:14:08 6188 534.0
## 4 20983533 2018-10-01 00:05:48 2018-10-01 00:18:46 6372 778.0
## 5 20983534 2018-10-01 00:07:29 2018-10-01 00:25:51 1927 1,102.0
## 6 20983535 2018-10-01 00:07:36 2018-10-01 00:11:25 2392 229.0
## from_station_id from_station_name to_station_id
## 1 85 Michigan Ave & Oak St 166
## 2 13 Wilton Ave & Diversey Pkwy 144
## 3 59 Wabash Ave & Roosevelt Rd 197
## 4 328 Ellis Ave & 58th St 419
## 5 93 Sheffield Ave & Willow St 159
## 6 229 Southport Ave & Roscoe St 318
## to_station_name usertype gender birthyear
## 1 Ashland Ave & Wrightwood Ave Subscriber Male 1992
## 2 Larrabee St & Webster Ave Subscriber Female 1982
## 3 Michigan Ave & Madison St Subscriber Male 1986
## 4 Lake Park Ave & 53rd St Subscriber Female 1960
## 5 Claremont Ave & Hirsch St Subscriber Female 1993
## 6 Southport Ave & Irving Park Rd Subscriber Male 1992
#head(connections)
nrow(trips)
## [1] 344940
trips %>% group_by(from_station_id,to_station_id) %>% count(name="trips")->trips_freq
#connections[connections$member1=="220654721",]
#setnames(trips_freq,old="n",new="weight")
trips_freq
## # A tibble: 50,971 x 3
## # Groups: from_station_id, to_station_id [50,971]
## from_station_id to_station_id trips
## <int> <int> <int>
## 1 2 2 53
## 2 2 3 34
## 3 2 4 7
## 4 2 5 4
## 5 2 6 7
## 6 2 7 9
## 7 2 14 1
## 8 2 24 1
## 9 2 25 1
## 10 2 26 4
## # ... with 50,961 more rows
its impossible to plot 50K trips on a markdown. But lets give it a try!!!
tripsNW <- graph_from_data_frame(trips_freq[,c(1,2)],directed=TRUE)
plot(tripsNW)#,vertex.label=NA)
plot(tripsNW,vertex.label=NA,layout=layout_in_circle)
we could also try arc diagrams, which are again useless in this case.
the Node properties are:
Degree centrality: how many other nodes are immediately connected to a node in focus. Closeness Centrality: 1/(sum of distances of all other nodes) betweenness centrality: sigma(for every pair of nodes except the node under consideration)(number of shortest distance that pass through the node under consideration/total number of shortest distances) in simple terms betweenness, centrality and shortest connectivity of a node to all other nodes. intutively these nodes are like hubs in airways shortest distance to all the other nodes for a given paths.
btwns<-betweenness(tripsNW,directed = TRUE)
#sort(btwns, decreasing = TRUE)
length(btwns)
## [1] 597
x<-unique(trips[,c(6,7)])
btwnness.df<-as.data.frame(stack(sort(btwns, decreasing = TRUE)))
names(btwnness.df)[2]<-"area_code"
rownames(btwnness.df) <- 1:nrow(btwnness.df) #reset index because we have changed the old index to column
x[[1]]<-as.character(x$from_station_id)
btwnness.df$area_code<-as.character(btwnness.df$area_code)
btwnness.df %>% left_join(x,by = c("area_code" = "from_station_id")) -> btwnness.df.names
btwnness.df.names%>%arrange(desc(values))
## values area_code from_station_name
## 1 8230.889146 211 St. Clair St & Erie St
## 2 8089.006798 35 Streeter Dr & Grand Ave
## 3 6052.682669 424 Museum of Science and Industry
## 4 5101.410378 90 Millennium Park
## 5 4951.041478 11 Jeffery Blvd & 71st St
## 6 4795.228953 429 Cottage Grove Ave & 67th St
## 7 4708.181813 247 Shore Dr & 55th St
## 8 4662.264716 392 Perry Ave & 69th St
## 9 4019.989523 44 State St & Randolph St
## 10 4001.390748 283 LaSalle St & Jackson Blvd
## 11 3995.798026 69 Damen Ave & Pierce Ave
## 12 3667.227487 585 Cottage Grove Ave & 83rd St
## 13 3625.341667 388 Halsted St & 63rd St
## 14 3603.723551 75 Canal St & Jackson Blvd
## 15 3599.359508 331 Halsted St & Clybourn Ave (*)
## 16 3489.271540 59 Wabash Ave & Roosevelt Rd
## 17 3358.018328 85 Michigan Ave & Oak St
## 18 3292.058332 345 Lake Park Ave & 56th St
## 19 3290.041117 284 Michigan Ave & Jackson Blvd
## 20 3281.298342 573 State St & 79th St
## 21 3264.782226 107 Desplaines St & Jackson Blvd
## 22 3146.603230 197 Michigan Ave & Madison St
## 23 3056.585988 91 Clinton St & Washington Blvd
## 24 3048.519299 81 Daley Center Plaza
## 25 2978.319332 77 Clinton St & Madison St
## 26 2928.920994 219 Damen Ave & Cortland St
## 27 2896.119659 192 Canal St & Adams St
## 28 2885.349060 76 Lake Shore Dr & Monroe St
## 29 2853.038181 36 Franklin St & Jackson Blvd
## 30 2829.153776 195 Columbus Dr & Randolph St
## 31 2823.767651 430 MLK Jr Dr & 63rd St
## 32 2784.503431 378 California Ave & Lake St
## 33 2741.681311 174 Canal St & Madison St
## 34 2738.995299 322 Kimbark Ave & 53rd St
## 35 2701.451039 24 Fairbanks Ct & Grand Ave
## 36 2690.809332 260 Kedzie Ave & Milwaukee Ave
## 37 2643.197784 99 Lake Shore Dr & Ohio St
## 38 2606.341470 43 Michigan Ave & Washington St
## 39 2594.511018 287 Franklin St & Monroe St
## 40 2573.548977 47 State St & Kinzie St
## 41 2570.323536 531 Central Ave & Lake St
## 42 2527.116927 52 Michigan Ave & Lake St
## 43 2502.033836 49 Dearborn St & Monroe St
## 44 2477.479559 112 Green St & Randolph St
## 45 2418.733828 594 Western Blvd & 48th Pl
## 46 2393.252555 303 Broadway & Cornelia Ave
## 47 2385.693987 4 Burnham Harbor
## 48 2336.681227 71 Morgan St & Lake St
## 49 2255.239413 255 Indiana Ave & Roosevelt Rd
## 50 2197.235647 117 Wilton Ave & Belmont Ave
## 51 2181.037498 212 Wells St & Hubbard St
## 52 2174.554304 426 Ellis Ave & 60th St
## 53 2172.641592 417 Cornell Ave & Hyde Park Blvd
## 54 2166.486602 61 Wood St & Milwaukee Ave
## 55 2136.391533 205 Paulina St & 18th St
## 56 2135.693773 210 Ashland Ave & Division St
## 57 2070.923752 51 Clark St & Randolph St
## 58 2045.957716 183 Damen Ave & Thomas St (Augusta Blvd)
## 59 2018.965918 12 South Shore Dr & 71st St
## 60 2017.856952 415 Calumet Ave & 51st St
## 61 2000.310029 427 Cottage Grove Ave & 63rd St
## 62 1992.393575 3 Shedd Aquarium
## 63 1982.085024 94 Clark St & Armitage Ave
## 64 1869.672602 299 Halsted St & Roscoe St
## 65 1818.043595 196 Cityfront Plaza Dr & Pioneer Ct
## 66 1813.044068 423 University Ave & 57th St
## 67 1812.056867 33 State St & Van Buren St
## 68 1797.361226 570 Evans Ave & 75th St
## 69 1794.119965 177 Theater on the Lake
## 70 1787.370814 420 Ellis Ave & 55th St
## 71 1784.262253 428 Dorchester Ave & 63rd St
## 72 1766.044084 199 Wabash Ave & Grand Ave
## 73 1750.394970 328 Ellis Ave & 58th St
## 74 1742.171172 289 Wells St & Concord Ln
## 75 1702.398322 198 Green St & Madison St
## 76 1698.694848 121 Blackstone Ave & Hyde Park Blvd
## 77 1676.156788 129 Blue Island Ave & 18th St
## 78 1665.954202 18 Wacker Dr & Washington St
## 79 1635.681380 156 Clark St & Wellington Ave
## 80 1622.273261 327 Sheffield Ave & Webster Ave
## 81 1610.774652 37 Dearborn St & Adams St
## 82 1585.666882 317 Wood St & Taylor St
## 83 1565.522613 545 Kostner Ave & Adams St
## 84 1553.066515 128 Damen Ave & Chicago Ave
## 85 1553.035343 419 Lake Park Ave & 53rd St
## 86 1551.357569 39 Wabash Ave & Adams St
## 87 1538.160365 123 California Ave & Milwaukee Ave
## 88 1507.570857 214 Damen Ave & Grand Ave
## 89 1492.287622 625 Chicago Ave & Dempster St
## 90 1477.951992 134 Peoria St & Jackson Blvd
## 91 1454.747770 463 Clark St & Berwyn Ave
## 92 1422.150185 280 Morgan St & 31st St
## 93 1406.377759 461 Broadway & Ridge Ave
## 94 1402.387496 406 Lake Park Ave & 35th St
## 95 1389.953461 229 Southport Ave & Roscoe St
## 96 1386.168607 395 Jeffery Blvd & 76th St
## 97 1380.101453 459 Lakefront Trail & Bryn Mawr Ave
## 98 1372.875159 344 Ravenswood Ave & Lawrence Ave
## 99 1366.560322 144 Larrabee St & Webster Ave
## 100 1357.039391 623 Michigan Ave & 8th St
## 101 1354.538545 194 Wabash Ave & Wacker Pl
## 102 1344.735693 268 Lake Shore Dr & North Blvd
## 103 1321.387291 339 Emerald Ave & 31st St
## 104 1315.034697 457 Clark St & Elmdale Ave
## 105 1311.715627 248 Woodlawn Ave & 55th St
## 106 1308.853265 638 Clinton St & Jackson Blvd (*)
## 107 1295.152717 26 McClurg Ct & Illinois St
## 108 1286.913967 145 Mies van der Rohe Way & Chestnut St
## 109 1278.946872 110 Dearborn St & Erie St
## 110 1266.868417 451 Sheridan Rd & Loyola Ave
## 111 1265.449362 239 Western Ave & Leland Ave
## 112 1264.396727 271 Cottage Grove Ave & 43rd St
## 113 1264.211594 321 Wabash Ave & 9th St
## 114 1254.581617 399 South Shore Dr & 74th St
## 115 1233.970696 230 Lincoln Ave & Roscoe St
## 116 1232.027524 334 Lake Shore Dr & Belmont Ave
## 117 1227.936373 458 Broadway & Thorndale Ave
## 118 1225.951155 438 Central Park Ave & Ogden Ave
## 119 1221.924876 298 Lincoln Ave & Belle Plaine Ave
## 120 1219.659668 460 Clark St & Bryn Mawr Ave
## 121 1216.678785 142 McClurg Ct & Erie St
## 122 1213.471542 577 Stony Island Ave & South Chicago Ave
## 123 1202.110264 108 Halsted St & Polk St
## 124 1197.080540 100 Orleans St & Merchandise Mart Plaza
## 125 1196.681305 16 Paulina Ave & North Ave
## 126 1182.150641 282 Halsted St & Maxwell St
## 127 1179.189788 352 Jeffery Blvd & 67th St
## 128 1177.460785 150 Fort Dearborn Dr & 31st St
## 129 1144.741929 383 Ashland Ave & Harrison St
## 130 1135.969444 13 Wilton Ave & Diversey Pkwy
## 131 1135.507436 114 Sheffield Ave & Waveland Ave
## 132 1134.619179 300 Broadway & Barry Ave
## 133 1134.265549 272 Indiana Ave & 31st St
## 134 1132.974174 140 Dearborn Pkwy & Delaware Pl
## 135 1130.514967 258 Logan Blvd & Elston Ave
## 136 1123.840300 56 Desplaines St & Kinzie St
## 137 1114.023715 390 Wentworth Ave & 63rd St
## 138 1107.851166 304 Broadway & Waveland Ave
## 139 1105.832008 220 Clark St & Drummond Pl
## 140 1101.156769 131 Lincoln Ave & Belmont Ave
## 141 1080.894164 120 Wentworth Ave & Cermak Rd (Temp)
## 142 1080.816588 97 Field Museum
## 143 1074.086653 53 Wells St & Huron St
## 144 1073.296725 418 Ellis Ave & 53rd St
## 145 1052.257176 57 Clinton St & Roosevelt Rd
## 146 1052.041136 2 Buckingham Fountain
## 147 1035.356416 58 Marshfield Ave & Cortland St
## 148 1031.248414 293 Broadway & Wilson Ave
## 149 1029.286824 164 Franklin St & Lake St
## 150 1012.964440 133 Kingsbury St & Kinzie St
## 151 999.976981 340 Clark St & Wrightwood Ave
## 152 996.717160 291 Wells St & Evergreen Ave
## 153 968.690829 294 Broadway & Berwyn Ave
## 154 966.329884 181 LaSalle St & Illinois St
## 155 962.857398 349 Halsted St & Wrightwood Ave
## 156 955.748625 243 Lincoln Ave & Sunnyside Ave
## 157 953.285340 267 Lake Park Ave & 47th St
## 158 945.730463 141 Clark St & Lincoln Ave
## 159 945.300799 66 Clinton St & Lake St
## 160 942.374587 454 Broadway & Granville Ave
## 161 934.314433 227 Southport Ave & Waveland Ave
## 162 932.925052 354 Sheridan Rd & Greenleaf Ave
## 163 925.824634 135 Halsted St & 21st St
## 164 924.110490 368 Ashland Ave & Archer Ave
## 165 920.284399 337 Clark St & Chicago Ave
## 166 914.819138 566 Ashland Ave & 69th St
## 167 902.625227 273 Michigan Ave & 18th St
## 168 901.804413 176 Clark St & Elm St
## 169 901.241511 506 Spaulding Ave & Armitage Ave
## 170 896.010959 338 Calumet Ave & 18th St
## 171 894.740894 367 Racine Ave & 35th St
## 172 893.255335 29 Noble St & Milwaukee Ave
## 173 891.510805 518 Conservatory Dr & Lake St
## 174 874.545211 286 Franklin St & Quincy St
## 175 870.594481 575 Cottage Grove Ave & 78th St
## 176 868.565395 21 Aberdeen St & Jackson Blvd
## 177 868.522014 342 Wolcott Ave & Polk St
## 178 861.572365 241 Morgan St & Polk St
## 179 859.620272 447 Glenwood Ave & Morse Ave
## 180 854.770755 127 Lincoln Ave & Fullerton Ave
## 181 852.641678 158 Milwaukee Ave & Wabansia Ave
## 182 843.875070 296 Broadway & Belmont Ave
## 183 841.738273 226 Racine Ave & Belmont Ave
## 184 833.586347 45 Michigan Ave & Congress Pkwy
## 185 817.120247 425 Harper Ave & 59th St
## 186 816.363553 215 Damen Ave & Madison St
## 187 814.987994 411 Halsted St & 47th Pl
## 188 803.959448 148 State St & 33rd St
## 189 802.091898 41 Federal St & Polk St
## 190 796.136707 376 Artesian Ave & Hubbard St
## 191 792.238603 84 Milwaukee Ave & Grand Ave
## 192 787.289985 116 Western Ave & Winnebago Ave
## 193 778.219577 193 State St & 29th St
## 194 775.408162 596 Benson Ave & Church St
## 195 768.695750 38 Clark St & Lake St
## 196 766.908568 270 Stony Island Ave & 75th St
## 197 764.240179 552 Ashland Ave & McDowell Ave
## 198 762.344529 184 State St & 35th St
## 199 761.263186 166 Ashland Ave & Wrightwood Ave
## 200 760.108297 242 Damen Ave & Leland Ave
## 201 751.205656 130 Damen Ave & Division St
## 202 748.463528 601 Central St Metra
## 203 748.185051 619 Keystone Ave & Fullerton Ave
## 204 737.429752 231 Sheridan Rd & Montrose Ave
## 205 733.869752 125 Rush St & Hubbard St
## 206 731.713932 534 Karlov Ave & Madison St
## 207 729.766507 635 Fairbanks St & Superior St (*)
## 208 718.098551 359 Larrabee St & Division St
## 209 713.510992 547 Ashland Ave & Pershing Rd
## 210 709.496112 326 Clark St & Leland Ave
## 211 708.342972 98 LaSalle St & Washington St
## 212 706.307554 324 Stockton Dr & Wrightwood Ave
## 213 699.587121 563 Ashland Ave & 63rd St
## 214 699.420663 54 Ogden Ave & Chicago Ave
## 215 692.873846 173 Mies van der Rohe Way & Chicago Ave
## 216 687.941435 208 Ashland Ave & 21st St
## 217 681.188438 165 Clark St & Grace St
## 218 680.312798 225 Halsted St & Dickens Ave
## 219 679.882818 25 Michigan Ave & Pearson St
## 220 676.267215 279 Halsted St & 35th St (*)
## 221 670.590908 5 State St & Harrison St
## 222 670.436473 597 Chicago Ave & Washington St
## 223 669.940702 14 Morgan St & 18th St
## 224 665.605531 126 Clark St & North Ave
## 225 662.571844 405 Wentworth Ave & 35th St
## 226 657.807149 249 Montrose Harbor
## 227 654.659130 336 Cottage Grove Ave & 47th St
## 228 654.465758 307 Southport Ave & Clybourn Ave
## 229 651.021019 233 Sangamon St & Washington Blvd (*)
## 230 649.817523 72 Wabash Ave & 16th St
## 231 649.492688 356 Stony Island Ave & 71st St
## 232 649.368447 115 Sheffield Ave & Wellington Ave
## 233 646.178801 621 Aberdeen St & Randolph St
## 234 646.046888 355 South Shore Dr & 67th St
## 235 643.724033 60 Dayton St & North Ave
## 236 643.156791 172 Rush St & Cedar St
## 237 642.810111 48 Larrabee St & Kingsbury St
## 238 641.468394 313 Lakeview Ave & Fullerton Pkwy
## 239 638.340506 132 Wentworth Ave & 24th St
## 240 637.810402 543 Laramie Ave & Gladys Ave
## 241 636.535066 595 Wabash Ave & 87th St
## 242 631.785877 161 Rush St & Superior St
## 243 630.425283 106 State St & Pearson St
## 244 619.292022 413 Woodlawn Ave & Lake Park Ave
## 245 615.489795 244 Ravenswood Ave & Irving Park Rd
## 246 613.756696 62 McCormick Place
## 247 613.270682 96 Desplaines St & Randolph St
## 248 612.893720 203 Western Ave & 21st St
## 249 610.969568 6 Dusable Harbor
## 250 602.298496 160 Campbell Ave & North Ave
## 251 601.799834 124 Damen Ave & Cullerton St
## 252 600.173036 578 Bennett Ave & 79th St
## 253 596.001138 232 Pine Grove Ave & Waveland Ave
## 254 588.714793 341 Adler Planetarium
## 255 588.264840 20 Sheffield Ave & Kingsbury St
## 256 588.000000 582 Phillips Ave & 83rd St
## 257 587.416371 87 Racine Ave & Fullerton Ave
## 258 587.000000 554 Damen Ave & 51st St
## 259 585.352100 31 Franklin St & Chicago Ave
## 260 580.071789 216 California Ave & Division St
## 261 573.094812 74 Kingsbury St & Erie St
## 262 563.156764 119 Ashland Ave & Lake St (Temp)
## 263 562.403103 153 Southport Ave & Wellington Ave
## 264 560.744865 157 Lake Shore Dr & Wellington Ave
## 265 557.179461 42 Wabash Ave & Cermak Rd
## 266 552.342839 265 Cottage Grove Ave & Oakwood Blvd
## 267 549.557633 257 Lincoln Ave & Waveland Ave
## 268 548.519777 152 Lincoln Ave & Diversey Pkwy
## 269 546.488941 191 Canal St & Monroe St (*)
## 270 546.035263 109 900 W Harrison St
## 271 545.844243 555 Ashland Ave & 50th St
## 272 543.293921 325 Clark St & Winnemac Ave (Temp)
## 273 541.163755 80 Aberdeen St & Monroe St
## 274 537.463541 234 Clark St & Montrose Ave
## 275 533.329250 101 63rd St Beach
## 276 532.341819 374 Western Ave & Walton St
## 277 532.229178 15 Racine Ave & 18th St
## 278 531.449069 9 Leavitt St & Archer Ave
## 279 528.933190 7 Field Blvd & South Water St
## 280 527.654086 46 Wells St & Walton St
## 281 514.953589 532 Austin Blvd & Lake St
## 282 501.991719 370 Calumet Ave & 21st St
## 283 501.693456 530 Laramie Ave & Kinzie St
## 284 501.337782 442 California Ave & 23rd Pl
## 285 500.181996 626 Delano Ct & Roosevelt Rd
## 286 493.989769 315 Elston Ave & Wabansia Ave
## 287 485.781111 88 Racine Ave & Randolph St
## 288 484.101032 118 Sedgwick St & North Ave
## 289 483.010429 17 Honore St & Division St
## 290 481.881660 464 Damen Ave & Foster Ave
## 291 481.376608 544 Austin Blvd & Madison St
## 292 478.143008 67 Sheffield Ave & Fullerton Ave
## 293 470.952779 329 Lake Shore Dr & Diversey Pkwy
## 294 469.706571 620 Orleans St & Chestnut St (NEXT Apts)
## 295 466.315253 346 Ada St & Washington Blvd
## 296 464.255742 93 Sheffield Ave & Willow St
## 297 464.133553 639 Lakefront Trail & Wilson Ave
## 298 458.762083 213 Leavitt St & North Ave
## 299 454.919813 515 Paulina St & Howard St
## 300 454.696117 228 Damen Ave & Melrose Ave
## 301 454.113677 350 Ashland Ave & Chicago Ave
## 302 451.990387 143 Sedgwick St & Webster Ave
## 303 443.408798 422 DuSable Museum
## 304 442.908881 453 Clark St & Schreiber Ave
## 305 442.194076 55 Halsted St & Roosevelt Rd
## 306 436.448077 113 Bissell St & Armitage Ave
## 307 432.883685 188 Greenview Ave & Fullerton Ave
## 308 432.655281 253 Winthrop Ave & Lawrence Ave
## 309 426.881784 261 Hermitage Ave & Polk St
## 310 425.505832 240 Sheridan Rd & Irving Park Rd
## 311 417.806950 502 California Ave & Altgeld St
## 312 415.154948 168 Michigan Ave & 14th St
## 313 413.116124 256 Broadway & Sheridan Rd
## 314 410.349053 323 Sheridan Rd & Lawrence Ave
## 315 402.499387 136 Racine Ave & 13th St
## 316 398.899344 332 Burling St (Halsted) & Diversey Pkwy (Temp)
## 317 397.832008 34 Cannon Dr & Fullerton Ave
## 318 396.231480 320 Loomis St & Lexington St
## 319 388.520619 302 Sheffield Ave & Wrightwood Ave
## 320 387.490824 295 Broadway & Argyle St
## 321 383.871926 40 LaSalle St & Adams St
## 322 382.780093 22 May St & Taylor St
## 323 382.117641 28 Larrabee St & Menomonee St
## 324 380.343052 222 Milwaukee Ave & Rockwell St
## 325 380.072252 186 Ogden Ave & Race Ave
## 326 374.578847 68 Clinton St & Tilden St
## 327 374.476222 254 Pine Grove Ave & Irving Park Rd
## 328 367.197974 50 Clark St & Congress Pkwy
## 329 364.589854 624 Dearborn St & Van Buren St (*)
## 330 364.170806 467 Western Ave & Lunt Ave
## 331 359.196171 180 Ritchie Ct & Banks St
## 332 358.501664 201 Indiana Ave & 40th St
## 333 347.331060 482 Campbell Ave & Montrose Ave
## 334 344.304146 223 Clifton Ave & Armitage Ave
## 335 339.935625 529 Cicero Ave & Lake St
## 336 338.348152 377 Kedzie Ave & Lake St
## 337 338.022704 182 Wells St & Elm St
## 338 337.398090 535 Pulaski Rd & Congress Pkwy
## 339 330.359010 308 Seeley Ave & Roscoe St
## 340 328.836269 364 Larrabee St & Oak St
## 341 327.495396 73 Jefferson St & Monroe St
## 342 325.045119 264 Stetson Ave & South Water St
## 343 324.922878 147 Indiana Ave & 26th St
## 344 324.854954 631 Malcolm X College
## 345 324.850790 32 Racine Ave & Congress Pkwy
## 346 323.244175 490 Troy St & Elston Ave
## 347 323.006303 505 Winchester Ave & Elston Ave
## 348 322.279099 179 MLK Jr Dr & Pershing Rd
## 349 318.155690 310 Damen Ave & Charleston St
## 350 316.712648 162 Damen Ave & Wellington Ave
## 351 314.067789 348 California Ave & 21st St
## 352 312.310851 314 Ravenswood Ave & Berteau Ave
## 353 311.216762 444 Albany Ave & 26th St
## 354 308.427295 333 Ashland Ave & Blackhawk St
## 355 307.388411 306 Sheridan Rd & Buena Ave
## 356 306.708347 483 Avondale Ave & Irving Park Rd
## 357 302.090552 202 Halsted St & 18th St
## 358 300.044231 381 Western Ave & Monroe St
## 359 298.895200 163 Damen Ave & Clybourn Ave
## 360 298.231084 171 May St & Cullerton St
## 361 298.048726 86 Eckhart Park
## 362 297.152200 27 Larrabee St & North Ave
## 363 294.550944 382 Western Ave & Congress Pkwy
## 364 294.229283 432 Clark St & Lunt Ave
## 365 292.863263 276 California Ave & North Ave
## 366 292.786224 238 Wolcott (Ravenswood) Ave & Montrose Ave (*)
## 367 285.976816 507 Humboldt Blvd & Armitage Ave
## 368 285.192514 301 Clark St & Schiller St
## 369 283.064381 92 Carpenter St & Huron St
## 370 282.599415 622 California Ave & Cortez St
## 371 281.299493 237 MLK Jr Dr & 29th St
## 372 279.646238 330 Lincoln Ave & Addison St
## 373 277.596281 369 Wood St & 35th St
## 374 276.500394 285 Wood St & Hubbard St
## 375 275.870795 111 Sedgwick St & Huron St
## 376 274.308419 206 Halsted St & Archer Ave
## 377 273.231031 351 Cottage Grove Ave & 51st St
## 378 269.041780 491 Talman Ave & Addison St
## 379 262.946859 312 Clarendon Ave & Gordon Ter
## 380 262.840821 277 Ashland Ave & Grand Ave
## 381 259.405537 224 Halsted St & Willow St
## 382 259.235330 503 Drake Ave & Fullerton Ave
## 383 257.855931 316 Damen Ave & Sunnyside Ave
## 384 257.232779 497 Kimball Ave & Belmont Ave
## 385 255.958671 627 LaSalle Dr & Huron St (*)
## 386 253.074147 146 Loomis St & Jackson Blvd
## 387 252.646832 278 Wallace St & 35th St
## 388 249.506638 297 Paulina St & Montrose Ave
## 389 244.006135 465 Marine Dr & Ainslie St
## 390 239.105438 154 Southport Ave & Belmont Ave
## 391 237.729493 551 Hoyne Ave & 47th St
## 392 235.457040 236 Sedgwick St & Schiller St
## 393 234.859887 30 Ashland Ave & Augusta Blvd
## 394 232.159762 437 Washtenaw Ave & Ogden Ave (*)
## 395 231.381206 245 Clarendon Ave & Junior Ter
## 396 231.291139 290 Kedzie Ave & Palmer Ct
## 397 231.132261 217 Racine Ave (May St) & Fulton St
## 398 229.915548 305 Western Ave & Division St
## 399 227.715744 318 Southport Ave & Irving Park Rd
## 400 225.350231 493 Western Ave & Roscoe St
## 401 225.309364 207 Emerald Ave & 28th St
## 402 223.766071 137 Morgan Ave & 14th Pl
## 403 223.599786 178 State St & 19th St
## 404 223.273763 604 Sheridan Rd & Noyes St (NU)
## 405 220.429242 138 Clybourn Ave & Division St
## 406 219.005408 448 Warren Park East
## 407 218.943169 553 Elizabeth St & 47th St
## 408 218.238474 414 Canal St & Taylor St
## 409 215.145035 175 Wells St & Polk St
## 410 214.350613 159 Claremont Ave & Hirsch St
## 411 205.673736 167 Damen Ave & Coulter St
## 412 204.543790 275 Ashland Ave & 13th St
## 413 204.067018 450 Warren Park West
## 414 202.556734 641 Central Park Ave & Bloomingdale Ave
## 415 202.340835 412 Princeton Ave & 47th St
## 416 201.630937 504 Campbell Ave & Fullerton Ave
## 417 201.232810 288 Larrabee St & Armitage Ave
## 418 201.153073 122 Ogden Ave & Congress Pkwy
## 419 199.187554 500 Central Park Ave & Elbridge Ave
## 420 198.658923 443 Millard Ave & 26th St
## 421 197.633267 209 Normal Ave & Archer Ave
## 422 196.236251 572 State St & 76th St
## 423 195.023473 259 California Ave & Francis Pl
## 424 193.057163 403 Wentworth Ave & 33rd St
## 425 192.535797 89 Financial Pl & Congress Pkwy (Temp)
## 426 191.069562 292 Southport Ave & Clark St
## 427 190.587623 487 California Ave & Byron St
## 428 188.373025 19 Loomis St & Taylor St (*)
## 429 188.054110 250 Ashland Ave & Wellington Ave
## 430 187.899880 527 Western Ave & Howard St
## 431 187.439367 501 Richmond St & Diversey Ave
## 432 186.673178 636 Orleans St & Hubbard St (*)
## 433 182.822992 347 Ashland Ave & Grace St
## 434 181.066516 200 MLK Jr Dr & 47th St
## 435 175.201570 486 Oakley Ave & Irving Park Rd
## 436 172.526029 373 Kedzie Ave & Chicago Ave
## 437 168.709380 508 Central Park Ave & North Ave
## 438 165.240271 474 Christiana Ave & Lawrence Ave
## 439 164.543192 492 Leavitt St & Addison St
## 440 163.024003 394 Clark St & 9th St (AMLI)
## 441 159.651085 281 Western Ave & 24th St
## 442 156.639479 190 Southport Ave & Wrightwood Ave
## 443 156.370956 523 Eastlake Ter & Rogers Ave
## 444 155.382545 649 Stewart Ave & 63rd St (*)
## 445 152.466755 498 California Ave & Fletcher St
## 446 151.225101 410 Prairie Ave & 43rd St
## 447 150.352433 185 Stave St & Armitage Ave
## 448 150.210403 204 Prairie Ave & Garfield Blvd
## 449 148.539060 170 Clinton St & 18th St
## 450 148.220686 449 Clark St & Columbia Ave
## 451 146.460015 309 Leavitt St & Armitage Ave
## 452 144.570398 95 Stony Island Ave & 64th St
## 453 142.922708 398 Rainbow Beach
## 454 142.031854 476 Kedzie Ave & Leland Ave
## 455 140.195499 469 St. Louis Ave & Balmoral Ave
## 456 139.226923 311 Leavitt St & Lawrence Ave
## 457 139.219222 475 Washtenaw Ave & Lawrence Ave
## 458 135.907404 657 Wood St & Augusta Blvd
## 459 135.150949 478 Rockwell St & Eastwood Ave
## 460 130.423949 479 Drake Ave & Montrose Ave
## 461 129.889730 659 Leavitt St & Chicago Ave
## 462 128.521734 477 Manor Ave & Leland Ave
## 463 128.237406 481 California Ave & Montrose Ave
## 464 127.641509 466 Ridge Blvd & Touhy Ave
## 465 127.406292 637 Wood St & Chicago Ave (*)
## 466 127.059907 445 California Ave & 26th St
## 467 124.731169 319 Greenview Ave & Diversey Pkwy
## 468 123.042441 434 Ogden Ave & Roosevelt Rd
## 469 121.409976 246 Ashland Ave & Belle Plaine Ave
## 470 118.323098 472 Lincoln Ave & Winona St
## 471 116.668452 169 Canal St & Harrison St
## 472 116.326524 343 Racine Ave & Wrightwood Ave
## 473 115.717461 605 University Library (NU)
## 474 115.388635 263 Rhodes Ave & 32nd St
## 475 114.319689 480 Albany Ave & Montrose Ave
## 476 109.461437 517 Clark St & Jarvis Ave
## 477 107.068374 494 Kedzie Ave & Bryn Mawr Ave
## 478 106.751959 528 Pulaski Rd & Lake St
## 479 105.421112 23 Orleans St & Elm St (*)
## 480 105.084183 402 Shields Ave & 31st St
## 481 104.339652 511 Albany Ave & Bloomingdale Ave
## 482 102.335950 408 Union Ave & Root St
## 483 100.352117 660 Sheridan Rd & Columbia Ave
## 484 97.746070 401 Shields Ave & 28th Pl
## 485 94.242983 468 Budlong Woods Library
## 486 93.423109 484 Monticello Ave & Irving Park Rd
## 487 93.146485 335 Calumet Ave & 35th St
## 488 92.944601 485 Sawyer Ave & Irving Park Rd
## 489 92.243538 452 Western Ave & Granville Ave
## 490 90.266998 471 Francisco Ave & Foster Ave
## 491 90.204316 588 South Chicago Ave & 83rd St
## 492 89.750182 603 Chicago Ave & Sheridan Rd
## 493 87.852041 602 Central St & Girard Ave
## 494 86.635588 431 Eberhart Ave & 61st St
## 495 85.893709 548 Morgan St & Pershing Rd
## 496 84.459107 274 Racine Ave & 15th St
## 497 83.127333 441 Kedzie Ave & 24th St
## 498 81.068741 251 Clarendon Ave & Leland Ave
## 499 77.753660 499 Kosciuszko Park
## 500 77.032127 366 Loomis St & Archer Ave
## 501 76.072537 524 Austin Blvd & Chicago Ave
## 502 72.435830 509 Troy St & North Ave
## 503 71.388897 567 May St & 69th St
## 504 68.857425 514 Ridge Blvd & Howard St
## 505 67.458753 446 Western Ave & 28th St
## 506 66.236012 470 Kedzie Ave & Foster Ave
## 507 64.789863 462 Winchester (Ravenswood) Ave & Balmoral Ave
## 508 63.679950 262 Halsted St & 37th St
## 509 63.650804 593 Halsted St & 59th St
## 510 63.366294 252 Greenwood Ave & 47th St
## 511 62.916518 218 Wells St & 19th St
## 512 60.677844 580 Exchange Ave & 79th St
## 513 59.610705 149 Calumet Ave & 33rd St
## 514 59.599998 533 Central Park Blvd & 5th Ave
## 515 53.553355 102 Stony Island Ave & 67th St
## 516 52.932295 628 Walsh Park
## 517 52.389902 586 MLK Jr Dr & 83rd St
## 518 49.507368 496 Avers Ave & Belmont Ave
## 519 49.123756 489 Drake Ave & Addison St
## 520 48.659955 549 Marshfield Ave & 44th St
## 521 45.722808 495 Keystone Ave & Montrose Ave
## 522 41.764593 591 Kilbourn Ave & Milwaukee Ave
## 523 41.495006 416 Dorchester Ave & 49th St
## 524 40.030010 568 Normal Ave & 72nd St
## 525 39.429167 643 Smith Park (*)
## 526 39.214622 559 Racine Ave & Garfield Blvd
## 527 38.185003 592 Knox Ave & Montrose Ave
## 528 36.011171 365 Halsted St & North Branch St
## 529 35.982432 439 Kedzie Ave & 21st St
## 530 34.825385 391 Halsted St & 69th St
## 531 34.087910 654 Racine Ave & Washington Blvd (*)
## 532 33.051320 525 Glenwood Ave & Touhy Ave
## 533 31.659449 600 Dodge Ave & Church St
## 534 30.908077 560 Marshfield Ave & 59th St
## 535 30.905220 546 Damen Ave & Pershing Rd
## 536 30.213823 409 Shields Ave & 43rd St
## 537 27.609391 590 Kilbourn Ave & Irving Park Rd
## 538 26.720760 574 Eberhart (Vernon) Ave & 79th St
## 539 25.054610 103 Clinton St & Polk St (*)
## 540 24.259770 400 Cottage Grove Ave & 71st St
## 541 21.883165 510 Spaulding Ave & Division St
## 542 21.140136 564 Racine Ave & 65th St
## 543 19.502812 589 Milwaukee Ave & Cuyler Ave
## 544 19.313343 630 Kildare Ave & Montrose Ave
## 545 18.612098 520 Greenview Ave & Jarvis Ave
## 546 18.465766 421 MLK Jr Dr & 56th St (*)
## 547 17.977751 655 Hoyne Ave & Balmoral Ave
## 548 17.849734 436 Fairfield Ave & Roosevelt Rd
## 549 16.792622 353 Clark St & Touhy Ave
## 550 16.225811 576 Greenwood Ave & 79th St
## 551 15.540743 386 Halsted St & 56th St
## 552 14.600999 433 Kedzie Ave & Harrison St
## 553 14.563053 581 Commercial Ave & 83rd St
## 554 14.540507 407 State St & Pershing Rd
## 555 14.523873 396 Yates Blvd & 75th St
## 556 13.948198 456 2112 W Peterson Ave
## 557 13.661844 435 Kedzie Ave & Roosevelt Rd
## 558 12.960128 526 Oakley Ave & Touhy Ave
## 559 11.848119 455 Maplewood Ave & Peterson Ave
## 560 11.816591 562 Racine Ave & 61st St
## 561 11.234406 583 Stony Island Ave & 82nd St
## 562 10.966056 385 Princeton Ave & Garfield Blvd
## 563 10.776043 598 Elmwood Ave & Austin St
## 564 10.022573 488 Pulaski Rd & Eddy St (Temp)
## 565 9.691824 522 Bosworth Ave & Howard St
## 566 9.520574 375 Sacramento Blvd & Franklin Blvd
## 567 9.504047 599 Valli Produce - Evanston Plaza
## 568 7.750655 646 State St & 54th St
## 569 7.103098 542 Central Ave & Madison St
## 570 6.742181 536 Kostner Ave & Lake St
## 571 6.435114 656 Damen Ave & Walnut (Lake) St (*)
## 572 6.164699 440 Central Park Ave & 24th St
## 573 6.113960 550 Central Ave & Chicago Ave
## 574 5.476847 561 Damen Ave & 59th St
## 575 4.762779 640 Bernard St & Elston Ave
## 576 4.321203 361 DIVVY CASSETTE REPAIR MOBILE STATION
## 577 2.191231 658 Leavitt St & Division St (*)
## 578 1.967080 519 Wolcott Ave & Fargo Ave
## 579 1.853698 644 Western Ave & Fillmore St (*)
## 580 0.700000 571 Vernon Ave & 75th St
## 581 0.000000 384 Halsted St & 51st St
## 582 0.000000 537 Kenton Ave & Madison St
## 583 0.000000 539 Cicero Ave & Quincy St
## 584 0.000000 541 Central Ave & Harrison St
## 585 0.000000 557 Seeley Ave & Garfield Blvd
## 586 0.000000 569 Woodlawn Ave & 75th St
## 587 0.000000 579 Phillips Ave & 79th St
## 588 0.000000 584 Ellis Ave & 83rd St
## 589 0.000000 587 Wabash Ave & 83rd St
## 590 0.000000 648 Carpenter St & 63rd St
## 591 0.000000 650 Eggleston Ave & 69th St (*)
## 592 0.000000 661 Evanston Civic Center
## 593 0.000000 662 Dodge Ave & Mulford St
## 594 0.000000 393 <NA>
## 595 0.000000 360 <NA>
## 596 0.000000 397 <NA>
## 597 0.000000 538 <NA>
nrow(btwnness.df.names)
## [1] 597
lets geocode and see what inbetweenness represent in this context of brike sharing service on a map.
btwnness.df.names$from_station_name <- paste0(btwnness.df.names$from_station_name, ", chicago, illinois, united states")
register_google(key = "MY_KEY")
geodata_1<-mutate_geocode(btwnness.df.names,from_station_name)
#geodata_2<-geocodeVect(btwnness.df.names$from_station_name[401:597], service="bing", returntype="coordinates")
chicago<-get_map("Chicago",zoom = 11)
## Source : https://maps.googleapis.com/maps/api/staticmap?center=Chicago&zoom=11&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx-nLXhqJK_V7NoQeLYR_nXko
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Chicago&key=xxx-nLXhqJK_V7NoQeLYR_nXko
ggmap(chicago)+
geom_point(data = geodata_1[1:200,], aes(x = lon, y = lat), color = 'blue', size = 2,alpha=0.5)+
geom_point(data = geodata_1[400:597,], aes(x = lon, y = lat), color = 'red', size = 2,alpha=0.5)
## Warning: Removed 111 rows containing missing values (geom_point).
## Warning: Removed 115 rows containing missing values (geom_point).
now lets analyse places that have high inbetweenness and analyse the time and day of the rides at these places.
trips$from_station_id<-as.character(trips$from_station_id)
trips$to_station_id<-as.character(trips$to_station_id)
names(btwnness.df)[2]<-"station_id"
btwnness.df[1:100,]%>%inner_join(trips,by=c("station_id"="from_station_id"))->trips_btwnss_top100
btwnness.df[498:597,]%>%inner_join(trips,by=c("station_id"="from_station_id"))->trips_btwnss_bottom100
btwnness.df[1:100,]%>%inner_join(trips,by=c("station_id"="to_station_id"))->trips_btwnss_top100_to
btwnness.df[498:597,]%>%inner_join(trips,by=c("station_id"="to_station_id"))->trips_btwnss_bottom100_to
nrow(trips_btwnss_top100)
## [1] 133125
nrow(trips_btwnss_bottom100)
## [1] 4168
nrow(trips_btwnss_top100_to)
## [1] 132387
nrow(trips_btwnss_bottom100_to)
## [1] 4352
Hour <- as.POSIXlt(trips_btwnss_top100$start_time)$hour
hist(Hour, breaks=seq(0, 23), main="Start time (hour) of trips starting from top 100 places with high betweenness",col="#CEBADF")
Hour <- as.POSIXlt(trips_btwnss_top100_to$end_time)$hour
hist(Hour, breaks=seq(0, 23), main="End time (hour) of trips ending at top 100 places with high betweenness",col="#FF8000FF")
the peak hours are obviously 7-8AM and 4-5PM, because these could be the work related commute hours. on further analysis, we find that trips starting from these places are fewer than the trips ending at these places in the morning. we can surmise that these bike stations are close to work places. And, from the map plot we can infer that these places are at the heart of city and we see more demand at these places. furthermore, people starting from these places are more in the evening then in the morning.
Hour <- as.POSIXlt(trips_btwnss_bottom100$start_time)$hour
hist(Hour, breaks=seq(0, 23), main="start time (hour) of trips from bottom 100 places with high betweenness",col="#AABADF")
Hour <- as.POSIXlt(trips_btwnss_bottom100_to$end_time)$hour
hist(Hour, breaks=seq(0, 23), main="end time (hour) of trips to bottom 100 places with low betweenness", col="#FF9007AA")
when above graphs are compared with the previous graphs, a reverse patern will be very evident. in these graphs, the trips to these places in the evening hours are more than in the morning hour. also the demand is much less in thse places.
tym_diff <- (trips_btwnss_top100$end_time- trips_btwnss_top100$start_time)
units(tym_diff)<-"mins"
sum(tym_diff>360)
## [1] 194
hist(as.numeric(subset(tym_diff,tym_diff<150)),seq(0,150,2),xlim=c(0,100), main="time difference of rides for top 100 places with high betweenness",col="#FABBFD")
Above graph shows the duration histogram of the rides, which could be used to design a pricing model.
#arpack_options.maxiter=3000000
tripsNWUD <- graph_from_data_frame(trips_freq[,c(1,2)],directed=FALSE)
graph <- simplify(tripsNWUD)
communities<-fastgreedy.community(graph)
plot(communities,tripsNWUD)#,vertex.label=NA)
network properties: shortest path diameter of the network density cluster coeffient Communities: there are three algorithmns to find community: greedy method edge inbetweennes eigen vector
what are communities: communities are densely connected sub-networks in the parent network. in our case we used greedy algorithm, which is based on increase in modularity of sub-network at each increment of the node in the subnetwork until the modularity remains unchanged for any subsequent additi of node.
For this data-set we obtained 3 communities
length(unique(communities$names))
## [1] 597
max(communities$membership)
## [1] 3
subset(communities$names,communities$membership ==3)
## [1] "384" "386" "388" "391" "392" "395" "400" "430" "549" "551" "554"
## [12] "555" "557" "559" "560" "561" "562" "563" "564" "566" "567" "568"
## [23] "569" "570" "571" "572" "573" "574" "575" "577" "578" "579" "582"
## [34] "583" "584" "585" "586" "587" "593" "594" "595" "649" "650" "393"
#lets map these communities
#subset(communities$names,communities$membership ==3)%>% left_join(geodata_1,)
geodata_1[geodata_1$area_code %in% subset(communities$names,communities$membership ==1),]->c1
geodata_1[geodata_1$area_code %in% subset(communities$names,communities$membership ==2),]->c2
geodata_1[geodata_1$area_code %in% subset(communities$names,communities$membership ==3),]->c3
ggmap(chicago, scale=2 )+geom_point(data =c1, aes(x = lon, y = lat), color = 'blue', size = 1,alpha=0.5)+
geom_point(data = c2, aes(x = lon, y = lat), color = 'red', size = 1,alpha=0.5)+
geom_point(data = c3, aes(x = lon, y = lat), color = 'orange', size = 1,alpha=1)
## Warning: Removed 151 rows containing missing values (geom_point).
## Warning: Removed 151 rows containing missing values (geom_point).
## Warning: Removed 24 rows containing missing values (geom_point).
seems like, here, communities represent various neighborhoods: residential neighbourhood (red dots) such as lake view, lincoln park and edison park, which is moderately traversed by these bikers; the well travelled commercial area (blue dots) of chicago and the southern chicago, which seems to be the least traversed parts.
node.prop.df<-NULL
Clust_network<-graph.edgelist(as.matrix(trips[,c(6,8)]), directed=TRUE)
indegree <- degree(Clust_network,mode="in")
outdegree <- degree(Clust_network,mode="out")
closeness_in <- closeness(Clust_network, mode="in",normalized = TRUE)
## Warning in closeness(Clust_network, mode = "in", normalized = TRUE):
## At centrality.c:2784 :closeness centrality is not well-defined for
## disconnected graphs
btwn <- betweenness(Clust_network,normalized = TRUE)
pg_rank <- page_rank(Clust_network,damping = 0)
eigenv <- eigen_centrality(Clust_network, directed = TRUE, scale = T)
df<-data.frame(stations=names(indegree),indegree=indegree)
row.names(df)<-1:nrow(df)
df<-merge(df, data.frame(stations=names(outdegree),outdegree=outdegree), by = "stations")
df<-merge(df, data.frame(stations=names(closeness_in),closeness_in=closeness_in), by = "stations")
df<-merge(df, data.frame(stations=names(btwn),betweenness=btwn), by = "stations")
#df<-merge(df, data.frame(stations=names(eigenv$vector),eigen_values=eigenv$vector), by = "stations") ##########eigen centrality is irrelevant here
node.prop.df<-df
head(node.prop.df)
## stations indegree outdegree closeness_in betweenness
## 1 100 2401 3336 0.1708226 5.777492e-03
## 2 101 54 59 0.1555730 1.492470e-03
## 3 102 14 9 0.1430972 5.729107e-05
## 4 103 277 244 0.1609941 1.597724e-05
## 5 106 1021 1093 0.1681716 1.486740e-03
## 6 107 1503 1509 0.1702371 9.153928e-03
normalized_data<-scale(node.prop.df[,2:5])
Cluster_Variability <- matrix(nrow=15, ncol=1)
for (i in 1:15) Cluster_Variability[i]<- kmeans(normalized_data[] ,centers=i, nstart=i)$tot.withinss
plot(1:15, Cluster_Variability, type="b", xlab="Number of clusters", ylab="Within groups sum of squares")
fit<- kmeans(normalized_data, centers=4, iter.max=50, nstart=9)
node.prop.df <- cbind(node.prop.df, fit$cluster)
head(node.prop.df)
## stations indegree outdegree closeness_in betweenness fit$cluster
## 1 100 2401 3336 0.1708226 5.777492e-03 3
## 2 101 54 59 0.1555730 1.492470e-03 1
## 3 102 14 9 0.1430972 5.729107e-05 1
## 4 103 277 244 0.1609941 1.597724e-05 1
## 5 106 1021 1093 0.1681716 1.486740e-03 3
## 6 107 1503 1509 0.1702371 9.153928e-03 3
summaryBy(indegree~`fit$cluster`, data = node.prop.df,
FUN = list(mean))
## fit$cluster indegree.mean
## 1 1 235.0682353
## 2 2 3792.5384615
## 3 3 1304.8333333
## 4 4 0.8888889
summaryBy(outdegree~`fit$cluster`, data = node.prop.df,
FUN = list(mean))
## fit$cluster outdegree.mean
## 1 1 231.771765
## 2 2 3864.076923
## 3 3 1307.900000
## 4 4 2.111111
summaryBy(closeness_in~`fit$cluster`, data = node.prop.df,
FUN = list(mean))
## fit$cluster closeness_in.mean
## 1 1 0.155081925
## 2 2 0.172212139
## 3 3 0.168160211
## 4 4 0.001675666
summaryBy(betweenness~`fit$cluster`, data = node.prop.df,
FUN = list(mean))
## fit$cluster betweenness.mean
## 1 1 0.0012194900
## 2 2 0.0168514567
## 3 3 0.0038910413
## 4 4 0.0001842348
clusters 2 and 3 have high indegree and out degree, and ,moreover, cluster 3 has high inbetweenness compared to cluster 2.
stations in clusters with high in-degree and out-degree should be closely monitored for number of available bikes to maitain service quality.