bike2017<-bike2017 %>% select("StartStation.Id","EndStation.Id","Start.Date")
###merge coordinate
#########################################################################
a<- coor
colnames(a)<- c("StartStation.Id","s.lat","s.lon")
x<-join(bike2017,a)
## Joining by: StartStation.Id
aa<- coor
colnames(aa)<- c("EndStation.Id","e.lat","e.lon")
#a<-setnames(coor,old=c("id","lat","long"),new=c("EndStation.Id","e.lat","e.lon"))
#aa<-setnames(coor,old=c("id","lat","long"),new=c("StartStation.Id","s.lat","s.lon"))
z<-join(x,aa)
## Joining by: EndStation.Id
head(z)
## StartStation.Id EndStation.Id Start.Date s.lat s.lon
## 1 217 819 05/01/2017 07:04 51.51615 -0.0824224
## 2 819 217 04/01/2017 16:05 NA NA
## 3 217 819 04/01/2017 07:17 51.51615 -0.0824224
## 4 273 217 05/01/2017 16:02 51.50613 -0.1146864
## 5 217 819 06/01/2017 07:16 51.51615 -0.0824224
## 6 433 246 05/01/2017 21:05 51.52456 -0.1162790
## e.lat e.lon
## 1 NA NA
## 2 51.51615 -0.08242240
## 3 NA NA
## 4 51.51615 -0.08242240
## 5 NA NA
## 6 51.52285 -0.09999405
z<- na.omit(z)
x<- count(z,vars = c("StartStation.Id","EndStation.Id"))
bike2017<- join(z,x)
## Joining by: StartStation.Id, EndStation.Id
#################weekdays
bike2017$weekdays<-weekdays(
strptime(bike2017$Start.Date,format="%d/%m/%Y %H:%M",tz="UTC")
)
##########same start and end stations
bike2017$samestation<- rep(0,nrow(bike2017))
head(bike2017)
## StartStation.Id EndStation.Id Start.Date s.lat s.lon
## 1 273 217 05/01/2017 16:02 51.50613 -0.11468639
## 2 433 246 05/01/2017 21:05 51.52456 -0.11627900
## 3 594 433 05/01/2017 20:45 51.51387 -0.11777400
## 4 246 162 05/01/2017 13:00 51.52285 -0.09999405
## 5 246 358 04/01/2017 14:22 51.52285 -0.09999405
## 6 66 427 06/01/2017 14:01 51.51795 -0.10865743
## e.lat e.lon freq weekdays samestation
## 1 51.51615 -0.08242240 60 Thursday 0
## 2 51.52285 -0.09999405 43 Thursday 0
## 3 51.52456 -0.11627900 7 Thursday 0
## 4 51.51761 -0.12132841 17 Thursday 0
## 5 51.51643 -0.12433218 16 Wednesday 0
## 6 51.51397 -0.09294031 86 Friday 0
bike2017[1:40,]
## StartStation.Id EndStation.Id Start.Date s.lat s.lon
## 1 273 217 05/01/2017 16:02 51.50613 -0.11468639
## 2 433 246 05/01/2017 21:05 51.52456 -0.11627900
## 3 594 433 05/01/2017 20:45 51.51387 -0.11777400
## 4 246 162 05/01/2017 13:00 51.52285 -0.09999405
## 5 246 358 04/01/2017 14:22 51.52285 -0.09999405
## 6 66 427 06/01/2017 14:01 51.51795 -0.10865743
## 7 427 66 06/01/2017 12:40 51.51397 -0.09294031
## 8 171 128 06/01/2017 23:36 51.49162 -0.18675386
## 9 128 589 06/01/2017 19:08 51.49536 -0.18529652
## 10 393 127 05/01/2017 07:50 51.51733 -0.10360425
## 11 506 537 04/01/2017 18:11 51.51747 -0.07585500
## 12 439 506 04/01/2017 17:39 51.53380 -0.11867700
## 13 439 537 05/01/2017 17:41 51.53380 -0.11867700
## 14 423 297 06/01/2017 17:08 51.49456 -0.15393398
## 15 423 297 05/01/2017 17:02 51.49456 -0.15393398
## 16 451 115 04/01/2017 07:41 51.50472 -0.06353100
## 17 451 237 05/01/2017 07:43 51.50472 -0.06353100
## 18 115 458 04/01/2017 18:48 51.51423 -0.07353765
## 19 115 134 05/01/2017 18:08 51.51423 -0.07353765
## 20 717 200 04/01/2017 22:53 51.53659 -0.07588569
## 21 39 717 04/01/2017 18:43 51.52638 -0.07813092
## 22 200 58 04/01/2017 13:29 51.51492 -0.06607804
## 23 58 200 04/01/2017 12:04 51.52453 -0.07924808
## 24 321 732 04/01/2017 14:07 51.49786 -0.08160805
## 25 732 321 04/01/2017 12:38 51.50630 -0.08726299
## 26 138 191 05/01/2017 16:03 51.51228 -0.15743697
## 27 427 89 07/01/2017 09:06 51.51397 -0.09294031
## 28 703 354 06/01/2017 12:58 51.51506 -0.10534448
## 29 365 200 06/01/2017 17:58 51.53034 -0.10016800
## 30 189 18 04/01/2017 18:40 51.53167 -0.10991471
## 31 200 365 05/01/2017 08:51 51.51492 -0.06607804
## 32 177 24 04/01/2017 08:33 51.49616 -0.14094764
## 33 24 177 04/01/2017 17:10 51.51908 -0.12467840
## 34 167 24 05/01/2017 09:49 51.49395 -0.14762438
## 35 24 177 05/01/2017 17:33 51.51908 -0.12467840
## 36 268 24 06/01/2017 08:18 51.49320 -0.14413287
## 37 24 177 06/01/2017 17:10 51.51908 -0.12467840
## 38 1 195 06/01/2017 18:50 51.52916 -0.10997053
## 39 197 335 07/01/2017 09:06 51.50557 -0.11160670
## 40 606 341 04/01/2017 08:28 51.50420 -0.21094100
## e.lat e.lon freq weekdays samestation
## 1 51.51615 -0.08242240 60 Thursday 0
## 2 51.52285 -0.09999405 43 Thursday 0
## 3 51.52456 -0.11627900 7 Thursday 0
## 4 51.51761 -0.12132841 17 Thursday 0
## 5 51.51643 -0.12433218 16 Wednesday 0
## 6 51.51397 -0.09294031 86 Friday 0
## 7 51.51795 -0.10865743 76 Friday 0
## 8 51.49536 -0.18529652 6 Friday 0
## 9 51.48720 -0.17936900 27 Friday 0
## 10 51.51701 -0.09388536 9 Thursday 0
## 11 51.51793 -0.06793700 36 Wednesday 0
## 12 51.51747 -0.07585500 2 Wednesday 0
## 13 51.51793 -0.06793700 3 Thursday 0
## 14 51.49613 -0.10600086 4 Friday 0
## 15 51.49613 -0.10600086 4 Thursday 0
## 16 51.51423 -0.07353765 129 Wednesday 0
## 17 51.50844 -0.06717644 20 Thursday 0
## 18 51.50475 -0.05754400 32 Wednesday 0
## 19 51.50490 -0.06797000 25 Thursday 0
## 20 51.51492 -0.06607804 3 Wednesday 0
## 21 51.53659 -0.07588569 129 Wednesday 0
## 22 51.52453 -0.07924808 26 Wednesday 0
## 23 51.51492 -0.06607804 14 Wednesday 0
## 24 51.50630 -0.08726299 134 Wednesday 0
## 25 51.49786 -0.08160805 80 Wednesday 0
## 26 51.50312 -0.15352093 121 Thursday 0
## 27 51.52625 -0.12350961 3 Saturday 0
## 28 51.50677 -0.12370200 12 Friday 0
## 29 51.51492 -0.06607804 14 Friday 0
## 30 51.51477 -0.12221963 9 Wednesday 0
## 31 51.53034 -0.10016800 35 Thursday 0
## 32 51.51908 -0.12467840 54 Wednesday 0
## 33 51.49616 -0.14094764 29 Wednesday 0
## 34 51.51908 -0.12467840 24 Thursday 0
## 35 51.49616 -0.14094764 29 Thursday 0
## 36 51.51908 -0.12467840 5 Friday 0
## 37 51.49616 -0.14094764 29 Friday 0
## 38 51.50724 -0.10623750 5 Friday 0
## 39 51.51197 -0.12071876 19 Saturday 0
## 40 51.50810 -0.12602103 12 Wednesday 0
bike2017$samestation[which((bike2017$StartStation.Id==bike2017$EndStation.Id))]<- bike2017$freq[which((bike2017$StartStation.Id==bike2017$EndStation.Id))]
#############################################################
With own colour
map<- get_map(location = "London",source="google",maptype="roadmap",zoom = 11)
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=London&zoom=11&size=640x640&scale=2&maptype=roadmap&language=en-EN&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=London&sensor=false
ggmap(map)+
geom_segment(data=bike2017,aes(x=bike2017$s.lon,y=bike2017$s.lat,xend=bike2017$e.lon, yend=bike2017$e.lat,colour=bike2017$freq
),size=0.00001,alpha=0.01)+
xlim(range(bike2017$s.lon))+
ylim(range(bike2017$s.lat))+
scale_color_gradient2(low="aliceblue",mid="wheat",high="red4")+
geom_point(data=bike2017,aes(x=s.lon,y=s.lat,fill=bike2017$samestation),size=0.01,alpha=0.5)+
facet_wrap(~ weekdays)
## Scale for 'x' is already present. Adding another scale for 'x', which
## will replace the existing scale.
## Scale for 'y' is already present. Adding another scale for 'y', which
## will replace the existing scale.