LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Intermediate Interactive Data Visualization with plotly in R

Kurs anzeigen

Anleitung zur Übung

  • 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.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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 bearbeiten und ausführen