Augmenting the data: Route summary statistics
We have constructed a dataset that is nearly ready for visualization, route_hod
. Let's add in a few more variables that will be useful as cognostics as we anticipate interactively viewing the display.
This exercise is part of the course
Visualizing Big Data with Trelliscope in R
Exercise instructions
- For each route, calculate the total number of rides.
- For each route, calculate the difference between the mean hourly rides during the work week and the mean hourly rides during the weekend. Note that the variable
n
already is aggregated to counts per hour, so, for example, the workweek mean is calculated withmean(n[weekday == "workweek"])
. - For each route, add a variable containing a URL pointing to the route on Google Maps, using the provided
make_gmap_url
function, providing appropriate arguments from the data.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
library(trelliscopejs)
library(ggplot2)
library(dplyr)
# Function to construct a Google maps URL with cycling directions
make_gmap_url <- function(start_lat, start_lon, end_lat, end_lon) {
paste0("https://www.google.com/maps/dir/?api=1",
"&origin=", start_lat, ",", start_lon,
"&destination=", end_lat, ",", end_lon,
"&travelmode=bicycling")
}
# Compute tot_rides, weekday_diff, and map_url
route_hod_updated <- route_hod %>% ungroup() %>%
group_by(start_station_code, end_station_code) %>%
mutate(
tot_rides = sum(___),
weekday_diff = mean(n[weekday == "workweek"]) - ___,
map_url = ___)