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))
}
coorStart<- function(data=coor){
colnames(data)[colnames(data) == "id"] <- "StartStation.Id"
return(data)
}
Applying the function on data
2013
maplotStart(bikedata = bike2013,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.
2015
maplotStart(bikedata = bike2015,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.
## Warning: Removed 1 rows containing missing values (geom_rect).
## Warning: Removed 2011 rows containing missing values (geom_point).
2016
maplotStart(bikedata = bike2016,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.
## Warning: Removed 1 rows containing missing values (geom_rect).
## Warning: Removed 1713 rows containing missing values (geom_point).