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)
Este ejercicio forma parte del curso
Interactive Data Visualization with plotly in R
Instrucciones del ejercicio
- Use
group_by(),nest(), andmutate(), andmap2()to create a faceted scatterplot showingCritic_Scoreon the x-axis andUser_Scoreon the y-axis, where the facets are defined byPlatform. - Arrange the facets in a grid with 3 rows.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Create a faceted scatterplot of User_Score vs. Critic_Score with 3 rows
vgsales2016 %>%
___(___) %>%
___() %>%
mutate(
plot = ___(
___, ___,
\(data, Platform)
)) %>%
subplot(nrows = ___, shareY = TRUE, shareX = TRUE)