I am attempting to use r-plotly to make an interactive graph. I would like there to be a button to filter by groups specified in the data. In the example below, the button works to filter the data into group 1 and group 2, but the button for "All groups" does not display all of the data. Anyone have suggestions?
df <- tibble(x = c(1, 4, 2, 7), y = c(3, 1, 8, 4), group = c(2, 1, 1, 2))
fig <- plot_ly(data = df, type = "scatter", mode = "markers") %>%
add_trace(type = "scatter", mode = "markers", x=~x, y=~y,
transforms = list(
list(
type = "filter",
target = ~group,
operation = 'in',
value = unique(df$group)
)
)
) %>%
layout(
updatemenus = list(
list(
type = 'dropdown',
active = 0,
buttons = list(
list(method = "restyle",
args = list("transforms[0].value", unique(df$group)[2]),
label = "Group 1"),
list(method = "restyle",
args = list("transforms[0].value", unique(df$group)[1]),
label = "Group 2"),
list(method = "restyle",
args = list("transforms[0].value", unique(df$group)),
label = "All groups")
)
)
)
)
fig