Session Ready
Exercise

Automated faceting

In the previous exercise, you manually create a faceted scatterplot. This was not very tedious because you were only focused on two groups. However, there are 9 platforms in the vgsales2016 dataset, and it would be very tedious to manually code 9 scatterplots.

In this exercise, you will practice using the group_by() and do() commands to automate the process of creating a facetted scatterplot with 12 facets. Remember that the entire plotting command is embedded within do(), as shown in the template below:

data %>%
  group_by(factor) %>%
  do(
    plot = plot_ly(data = ., x = ~x, y = ~y) %>%
      add_markers(name = ~factor)
  ) %>%
  subplot(nrows = R, shareY = TRUE, shareX = TRUE)
Instructions
100 XP
  • Use group_by(), do(), and subplot() to create a faceted scatterplot showing Critic_Score on the x-axis and User_Score on the y-axis, where the facets are defined by Platform.
  • Arrange the facets in a grid with 3 rows.