Tip amount distribution faceted by payment type
The distribution of the total cab fare plot we created earlier was interesting, but we might be able to gain additional insight into this distribution by investigating whether it varies with respect to another variable. In this exercise, we'll look at the tip amount portion of the cab fare distribution and see if it is different for different payment types by creating a histogram and faceting on payment type.
tx
is preloaded into your workspace for you.
Cet exercice fait partie du cours
Visualizing Big Data with Trelliscope in R
Instructions
- Create a histogram of
tip_amount + 0.01
(a cent to each tip because we will take a log transform and there are tips that are zero). - Use
scale_x_log10()
to transform the x-axis. - Use
facet_wrap()
to facet bypayment_type
. To help visually compare distributions, set the number of columns to1
and make the y-axis scales free by specifying the scales to be"free_y"
.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
library(ggplot2)
# Histogram of the tip amount faceted on payment type
ggplot(___, aes(___)) +
___ +
___ +
facet_wrap(~ ___, ncol = ___, scales = ___)