Here is an example of using biker
:
library(bikesR) ans1 = loadBikes(range = '05Jul2017-11Jul2017') knitr::kable(head(ans1$hourlyRentals, 10))
There are several outputs from the load data function, some of which can be fitted using the internal function fit.
You can fit and plot the data using loess, splines, arima.
ans2 = fit(ans1, data_type = 'hourlyRentals', fit_type = 'smooth.spline') plot(ans2) ans3 = fit(ans1, data_type = 'dailyRentals', fit_type = 'loess') plot(ans3) ans4 = fit(ans1, data_type = 'hourlyRentals', fit_type = 'arima') plot(ans4)
loess and smoothing splines function calls allow you to pass in smoothing parameters
ans2 = fit(ans1, data_type = 'hourlyRentals', fit_type = 'smooth.spline', spar = 0.5) # plot(ans2) ans3 = fit(ans1, data_type = 'dailyRentals', fit_type = 'loess', span = 5) # plot(ans3)
Others are used for exploratory data analysis and can also be plotted on spatial visualisations.
knitr::kable(head(ans1$stationStats, 10)) map.biker(obj = ans1, data_type = 'stationStats', 'usage') map.biker(obj = ans1, data_type = 'stationStats', 'rentals')
You can use the package in conjunction with other spatial packages (ggmap) and view for example the route of a bike.
require(ggmap) # wrapper function for ggmap's route which returns the geocoordinates of the route created by the route function. getRoute <- function(df, id){ cbind(BikeId = id, route(from = c(as.character(df$StartStationName)), to = c(as.character(df$EndStationName)) ,structure = "legs")) } # Lets trace the journey of a single bike over the course of the week sample = getRoute(ans1$data, id = 1) # get potential routes between each station the bike has visited map <- get_map(location = 'London', zoom = 12) ggmap(map, base_layer = ggplot(aes(x = endLon, y = endLat),data = sample)) + geom_leg(data = sample, aes(x = startLon, y = startLat, xend = endLon, yend = endLat), alpha = 3/4 ) + labs(x = 'Longitude', y = 'Latitude') + ggtitle("Journey of a bike over the course of a week")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.