LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Visualizing Big Data with Trelliscope in R

Kurs anzeigen

Anleitung zur Übung

  • 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".

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

library(ggplot2)

# Histogram of the tip amount faceted on payment type
ggplot(___, aes(___)) +
  ___ +
  ___ +
  facet_wrap(~ ___, ncol = ___, scales = ___)
Code bearbeiten und ausführen