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 6 platforms in the vgsales2016 dataset, and it would be very tedious to manually code 6 scatterplots.

In this exercise, you will practice using group_by(), nest(), mutate(), and map2() to automate the process of creating a faceted scatterplot using the following template:

data %>%
  group_by(factor) %>%
  nest() %>%
  mutate(
      plot = map2(data, factor,
        \(data, factor) 
            plot_ly(data = data, x = ~x, y = ~y) %>%
                  add_markers(name = ~factor)
    )) %>%
  subplot(nrows = R, shareY = TRUE, shareX = TRUE)

Instructions

100 XP
  • Use group_by(), nest(), and mutate(), and map2() 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.