ComeçarComece de graça

Factors as frames

Time is not the only type of variable that can be used to specify the frames of an animation. You can also create an animation that cycles through subplots created by factors rather than using a grid layout.

In this exercise, you will adapt your answer from the previous question to create an animation that cycles through bubble charts for each region in 2017.

Note: The default settings for the animation make it go very quickly. In the next lesson, you'll learn how to adjust the speed. For now, you can use the slider bar to navigate between regions if you want to investigate the relationships.

plotly and the us_economy data set have already been loaded.

Este exercício faz parte do curso

Intermediate Interactive Data Visualization with plotly in R

Ver curso

Instruções do exercício

Complete the code to animate a bubble chart of house_price against gdp across regions of the U.S. Specifically,

  • filter out the data for 2017,
  • and change the appropriate aesthetic to allow region to define each snapshot in the animation.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Animate a bubble chart of house_price against gdp over region
us_economy %>%
  ___(___ == ___) %>%
  plot_ly(x = ~gdp, y = ~house_price) %>%
  add_markers(size = ~population, color = ~region, 
              frame = ___, ids = ~state,
              marker = list(sizemode = "diameter"))
Editar e executar o código