Function for season

#########season function
Season <- function(data2) {
  d<- as.Date(strptime(data2$Start.Date,format="%d/%m/%Y %H:%M",tz="UTC"))
  WS <- as.Date("21/12/2017", format = "%d/%m/%Y") # Winter 
  SE <- as.Date("20/3/2017",  format = "%d/%m/%Y") # Spring 
  SS <- as.Date("21/6/2017",  format = "%d/%m/%Y") # Summer 
  FE <- as.Date("22/9/2017",  format = "%d/%m/%Y") # Fall
  
  ifelse (d >= WS | d < SE, "Winter",
          ifelse (d >= SE & d < SS, "Spring",
                  ifelse (d >= SS & d < FE, "Summer", "Autumn")))
}

Function to get data manipulated

seasonweekdata<- function(data1,coordinates=coor){
  data1<-data1 %>% 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")
  )
  data1$season<-Season(data2=data1)
  
  ########################################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

wfullplot<- function( source="google",maptype="roadmap",zoom=11){

  
  q<- seasonweekdata(data1 = bikedata)
  #Winter<- q[q$season=="Winter",]
  #Spring<- q[q$season=="Spring",]
  Summer<- q[q$season=="Summer",]
  #Autumn<- q[q$season=="Autumn",]
  ######################starting station
  s.top<- dplyr::select(Summer,"s.lat","s.lon","StartStation.Name")
  sc<- count(s.top$StartStation.Name)
  colnames(sc)<- c("StartStation.Name","Freq")
  scj<- join(sc,s.top)
  scj<- scj[!duplicated(scj),]
  scj<-arrange(scj,desc(Freq))[1:5,]
#########################ending station
  e.top<- dplyr::select(Summer,"e.lat","e.lon","EndStation.Name")
  ec<- count(e.top$EndStation.Name)
  colnames(ec)<- c("EndStation.Name","Freq1")
  ecj<- join(ec,e.top)
  ecj<- ecj[!duplicated(ecj),]
  ecj<-arrange(ecj,desc(Freq1))[1:5,]
  ############################################mapping
  map<- get_map(location = c(lon =mean(q$s.lon),lat = mean(q$s.lat)),
                source=source,maptype=maptype,zoom = zoom)
    ######################################Summer
  plot<-ggmap(map)+
    geom_segment(data=Summer,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 Summer bicycle trips")+
    theme(plot.title = element_text(hjust = 0.5))+

    xlim(range(q$s.lon))+
    ylim(range(q$s.lat))+
    geom_point(data=Summer,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=3,alpha=0.4
                    )+
                #    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=3,alpha=0.4)

  ############################################################summer
  
  return(plot)

  
}

Creating a frequency data

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

wfullplot()
## Joining by: StartStation.Id
## Joining by: EndStation.Id
## Joining by: StartStation.Id, EndStation.Id
## Joining by: StartStation.Name
## Joining by: EndStation.Name
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=51.508541,-0.12769&zoom=11&size=640x640&scale=2&maptype=roadmap&language=en-EN&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.