1. Learn
  2. /
  3. Courses
  4. /
  5. Foundations of Functional Programming with purrr

Connected

Exercise

purrr and histograms

Now you're going to put together everything you've learned, starting with two different lists, which will be turned into a faceted histogram. You're going to work again with the Stars Wars data from the sw_films and sw_people datasets to answer a question:

  • What is the distribution of heights of characters in each of the Star Wars films?

Different movies take place on different sets of planets, so you might expect to see different distributions of heights from the characters. Your first task is to transform the two datasets into data frames since ggplot() requires a data frame input. Then you will join them together, and plot the result, a histogram with a different facet, or subplot, for each film.

Instructions

100 XP
  • Create a data frame with the "title" of each film, and the "characters" from each film in the sw_films dataset.
  • Create a data frame with the "height", "mass", "name", and "url" elements from sw_people.
  • Join the two data frames together using the "characters" and "url" keys.
  • Create a ggplot() histogram with x = height, faceted by filmtitle.