Get startedGet started for free

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.

This exercise is part of the course

Visualizing Big Data with Trelliscope in R

View Course

Exercise 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 by payment_type. To help visually compare distributions, set the number of columns to 1 and make the y-axis scales free by specifying the scales to be "free_y".

Hands-on interactive exercise

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

library(ggplot2)

# Histogram of the tip amount faceted on payment type
ggplot(___, aes(___)) +
  ___ +
  ___ +
  facet_wrap(~ ___, ncol = ___, scales = ___)
Edit and Run Code