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
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 thepickup_date
,pickup_dow
,payment_type
. - Inside
summarise()
, count the number of rides and assign the result to a new variablen_rides
. - Plot the result using the
daily_count
summary dataset as an input toggplot()
and usinggeom_point()
, withpickup_date
on the x-axis andn_rides
on the y-axis. - Use
facet_grid()
to facet withpayment_type
as rows and day of weekpickup_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)