Function to get data manipulated

seasonweekdata<- function(data1,coordinates=coor){
  data1<-data1 %>% dplyr::select("StartStation.Id","EndStation.Id","Start.Date","StartStation.Name",
                          "EndStation.Name")
  
  ###merge coordinate
  #########################################################################
  a<- coor
  colnames(a)<- c("StartStation.Id","s.lat","s.lon")
  x<-join(data1,a)
  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)
  z<- na.omit(z)
  x<- count(z,vars = c("StartStation.Id","EndStation.Id"))
  data1<- join(z,x)
  #################weekdays############################################################
  data1$weekdays<-weekdays(
    strptime(data1$Start.Date,format="%d/%m/%Y %H:%M",tz="UTC")
  )

  ########################################seasons
  return(data1)
  ##########same start and end stations #########################################
  #attach(bikedata)
  # bikedata$samestation<- rep(0,nrow(bikedata))
  #head(bikedata)
  #bikedata$samestation[which((StartStation.Id==EndStation.Id))]<- bikedata$freq[which((StartStation.Id==EndStation.Id))]
  str(data1)
  
}

Function for plots

  q<- sample_n(seasonweekdata(data1 = bikedata),6233518)
## Joining by: StartStation.Id
## Joining by: EndStation.Id
## Joining by: StartStation.Id, EndStation.Id
  ######################starting station
  s.top<- dplyr::select(q,"s.lat","s.lon","StartStation.Name")
  sc<- count(s.top$StartStation.Name)
  colnames(sc)<- c("StartStation.Name","Freq")
  scj<- join(sc,s.top)
## Joining by: StartStation.Name
  scj<- scj[!duplicated(scj),]
  scj<-arrange(scj,desc(Freq))[1:5,]
#########################ending station
  e.top<- dplyr::select(q,"e.lat","e.lon","EndStation.Name")
  ec<- count(e.top$EndStation.Name)
  colnames(ec)<- c("EndStation.Name","Freq1")
  ecj<- join(ec,e.top)
## Joining by: EndStation.Name
  ecj<- ecj[!duplicated(ecj),]
  ecj<-arrange(ecj,desc(Freq1))[1:5,]

Creating a frequency data

q1<- q[1:(nrow(q)/2),]
q2<- q[3166760:6233518,]

map<- get_map(location = c(lon =mean(q$s.lon),lat = mean(q$s.lat)),
              source="google",maptype="roadmap",zoom=11)
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=51.508906,-0.125838&zoom=11&size=640x640&scale=2&maptype=roadmap&language=en-EN&sensor=false
plot<- ggmap(map)+
  geom_segment(data=q1,aes(x=s.lon,y=s.lat,xend=e.lon, yend=e.lat,alpha=freq),
               colour= "black",size=0.00001)+
  scale_alpha_continuous(range = c(0, 0.05))+
  ggtitle("2017 bicycle trips")+
  theme(plot.title = element_text(hjust = 0.5,size = 13))+
  
  xlim(range(q$s.lon))+
  ylim(range(q$s.lat))+
  geom_point(data=q1,aes(x=s.lon,y=s.lat),size=0.001,alpha=0.3)+
  
  geom_label_repel(data=scj, aes(x=s.lon,y=s.lat,label=StartStation.Name),
                   color="blue",nudge_y = 0.03,nudge_x = -0.1,label.size = 0.05,
                   size=5,alpha=0.6
  )+
  #    arrow =arrow(length =unit(0.5,"cm")))+
  geom_label_repel(data=ecj, aes(x=e.lon,y=e.lat,label=EndStation.Name),
                   color="red",segment.size = 0.5,segment.colour = "red",
                   #arrow = arrow(length = unit(0.5,"cm")),
                   nudge_y = -0.03,nudge_x = 0.15,size=5,alpha=0.6)
## 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.
plot1<- plot +   geom_segment(data=q2,aes(x=s.lon,y=s.lat,xend=e.lon, yend=e.lat,alpha=freq),
                              colour= "black",size=0.00001)+
  scale_alpha_continuous(range = c(0, 0.05))
## Scale for 'alpha' is already present. Adding another scale for 'alpha',
## which will replace the existing scale.
plot1

#sfullplot(zoom = 11,
 #        data5= topplace(data4 = Summer))