ComenzarEmpieza gratis

Adding a slider for time

In the previous lesson, you created an animation displaying the number of launches by each state over the years. A slider bar is an alternative to that animation that gives you full control over what portion of the story to investigate. For example, you can view it from beginning to end or focus only on the 1960s. In this exercise, your task is to add a slider bar below the line chart of state-based launches.

plotly, crosstalk, dplyr, and the state_launches data set have been loaded for you.

Este ejercicio forma parte del curso

Intermediate Interactive Data Visualization with plotly in R

Ver curso

Instrucciones del ejercicio

  • Calculate the number of launches by state_code and launch_year, and convert this to a SharedData object. Store the result in shared_launches.
  • Using shared_launches, create a line chart displaying the the number of launches (n) by each state over time. Store this chart as launch_ts. Use color to represent the state_code.
  • Position a slider below the chart to filter the years displayed. Label this slider "Year".

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# Create a SharedData object containing the number of launches by year and state
shared_launches <- state_launches %>%
  count(___, ___) %>%
  ___()

# Create a line chart displaying the launches by state
launch_ts <- ___ %>%
  ___(x = ___, y = ___, color = ___) %>%
  ___()  

# Add a slider below the chart to filter the years displayed
___(list(___,
    ___(id = "time", label = ___, 
        sharedData = ___, column = ___)
))
Editar y ejecutar código