Aan de slagGa gratis aan de slag

Adding checkboxes

Adding checkbox filters allows you to quickly "call out" a group, or set of groups, which is particularly useful when exploring how associations change between groups.

In this exercise, your task is to add a checkbox filter for the region to a scatterplot of the housing price index against homeownership in 2017.

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

Deze oefening maakt deel uit van de cursus

Intermediate Interactive Data Visualization with plotly in R

Cursus bekijken

Oefeninstructies

  • Add a checkbox filter for region to the left of the scatterplot stored in p17.
  • Restrict the width of the checkboxes to 3 columns, and allow the plot to span the remainder of the columns.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# shared data object
shared_us <- SharedData$new(us2017, key = ~region)

# scatterplot of housing price index against homeownership
p17 <- shared_us %>%
  plot_ly(x = ~home_owners, y = ~house_price, color = ~region, height = 400) %>%
  add_markers()
  
# add a column of checkboxes for region to the left of the plot
___(___,
  ___(id = "region", label = "Region", sharedData = ___, group = ___),
  p17
)
Code bewerken en uitvoeren