Aan de slagGa gratis aan de slag

Adding a slider

A slider filter allows you to easily update the data values plotted by restricting a numeric variable to a specific range. In this exercise, your task is to include two slider filters for the scatterplot of the housing price index against homeownership in 2017: one for each axis.

plotly and crosstalk have already been loaded for you, and the data are stored in us2017.

Note: You may need to scroll down on or pop out the HTML Viewer to see the sliders.

Deze oefening maakt deel uit van de cursus

Intermediate Interactive Data Visualization with plotly in R

Cursus bekijken

Oefeninstructies

  • Place two slider filters below the scatterplot stored in p17. The first slider should correspond to the housing price index (house_price), and the second slider should correspond to the percentage of home ownership (home_owners).
  • Add slider labels that match the axis titles in p17, "HPI" and "Home ownership (%)".

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

shared_us <- SharedData$new(us2017)
p17 <- shared_us %>%
  plot_ly(x = ~home_owners, y = ~house_price, 
          color = ~region, height = 400) %>%
  add_markers() %>%
  layout(xaxis = list(title = "Home ownership (%)"), 
         yaxis = list(title = "HPI"))
  
# add a slider filter for each axis below the scatterplot
___(
  ___(p17,
      ___(id = "price",  label = ___,  sharedData = ___,  column = ___),
      ___(id = "owners",  label = ___,  sharedData = ___, column = ___)
  )
)
Code bewerken en uitvoeren