Comparing fare distribution by payment type
We have seen that there is no tip for cash payments. Does this mean people who pay with cash don't tip, or does it mean that tips aren't recorded when people pay with cash? For similar routes, we would expect the distributions of total fare to be identical regardless of payment type. In this exercise, we will create a quantile plot comparing the distribution of total fare by payment type and compare that with the original plot in a different facet.
A dataset amount_compare
has been created for you that contains variables payment_type
, amount
, and amount_type
. amount_type
distinguishes between values that reflect a total payment vs. a payment with no tip.
This exercise is part of the course
Visualizing Big Data with Trelliscope in R
Exercise instructions
- Inspect the
amount_compare
dataset prior to completing the exercise by printing it to the console to understand its structure to help with the plot specification. - Use
geom_qq()
to create a quantile plot of the total fare amount,amount
. Be sure to specifydistribution = stats::qunif
. - Make sure separate quantile plots are made for each payment type by
color
ing by payment type such that each distribution is superposed on the same plot. - Show the distribution comparisons for each
amount_type
by faceting.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
library(ggplot2)
library(dplyr)
library(tidyr)
# Get data ready to plot
amount_compare <- tx_pop %>%
mutate(total_no_tip = total_amount - tip_amount) %>%
select(total_amount, total_no_tip, payment_type) %>%
pivot_longer(!payment_type, names_to = "amount_type", values_to = "amount")
# Quantile plot
ggplot(___, aes(sample = ___, color = ___)) +
geom_qq(distribution = ___, shape = 21) +
facet_wrap(~ ___) +
ylim(c(3, 20))