Get startedGet started for free

Faceting daily rides

We noticed some interesting behavior when we looked at daily ride counts faceted by day-of-week. Let's investigate whether faceting on additional variables yields any new insights. Here we will see if there are different day-of-week patterns when also looking at the payment types of cash or credit card.

tx is available for you in your workspace.

This exercise is part of the course

Visualizing Big Data with Trelliscope in R

View Course

Exercise instructions

  • After filtering to just cash and credit transactions, create a summary by day of week and payment type count using dplyr, grouping by the pickup_date, pickup_dow, payment_type.
  • Inside summarise(), count the number of rides and assign the result to a new variable n_rides.
  • Plot the result using the daily_count summary dataset as an input to ggplot() and using geom_point(), with pickup_date on the x-axis and n_rides on the y-axis.
  • Use facet_grid() to facet with payment_type as rows and day of week pickup_dow as columns.
  • Note that the coord_fixed() code constrains the aspect ratio of the resulting plot to help highlight patterns visually.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

library(dplyr)
library(ggplot2)

# Summarize taxi rides count by payment type, pickup date, pickup day of week
daily_count <- tx %>%
  filter(payment_type %in% c("Card", "Cash")) %>%
  group_by(___, ___, ___) %>%
  summarise(___)

# Plot the data
ggplot(___, aes(___, ___)) +
  ___ +
  facet_grid(___ ~ ___) +
  coord_fixed(ratio = 0.4)
Edit and Run Code