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.
Bu egzersiz
Visualizing Big Data with Trelliscope in R
kursunun bir parçasıdırEgzersiz talimatları
- 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_countsummary dataset as an input toggplot()and usinggeom_point(), withpickup_dateon the x-axis andn_rideson the y-axis. - Use
facet_grid()to facet withpayment_typeas rows and day of weekpickup_dowas columns. - Note that the
coord_fixed()code constrains the aspect ratio of the resulting plot to help highlight patterns visually.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
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)