Function for plotting the map of starting station

for ending stations, simply change the string name

maplotStart<- function(bikedata,coordata,station,source = "google",maptype="roadmap"){
  ######################keeping station
  
  bikedata<-bikedata %>% select("StartStation.Id")
  ###merge coordinates
  merged<- merge(bikedata,coordata,by="StartStation.Id")
  ####adding frequency 
  count<-data.frame(count(bikedata$StartStation.Id))
  colnames(count)[which(colnames(count) == 'x')] <- "StartStation.Id"
  #########################final merge with the frequency 
  bikedata<- merge(merged,count,by="StartStation.Id")
  bikedata<- na.omit(bikedata)
  
  #########################mapping 
  
  map<- get_map(location = "London",source = source,zoom = 11,
                maptype=maptype)
  ggmap(map)+
    geom_jitter(data=bikedata,aes(x=long,y=lat, colour=freq),alpha=0.1,size=0.9)+
    scale_color_gradient(low = "yellow",high = "black")+
    xlim(range(bikedata$long))+
    ylim(range(bikedata$lat))
  
}

Function for changing the name of the coordinates data (Conditional)

coo<- function(data=coor,station){
  colnames(data)[colnames(data) == "id"] <- station
  return(data)
}

coorStart<- function(data=coor){
  colnames(data)[colnames(data) == "id"] <- "StartStation.Id"
  return(data)
}

Applying the function on 2017bike data

maplotStart(bikedata = bike2017,coordata = coorStart(data=coor))
## 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
## 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.