I am trying to filter in r by characters in a column but I can’t get it to show all data in that column as a button also. I am also fitting a line to the data and would like to show all lines when the “All” button is pressed, and the lines be named accordingly.
Here is a sample:
library(plotly)
qfitspec <- lm(Petal.Length ~ poly(Sepal.Length, 1), data = iris)
p <- iris %>%
plot_ly(
type = 'scatter',
x = ~Sepal.Length,
y = ~Petal.Length,
text = ~Species,
hoverinfo = 'text',
mode = 'markers',
transforms = list(
list(
type = 'filter',
target = ~Species,
operation = '=',
value = unique(iris$Species)[1]
)
))%>%
add_lines(y = ~fitted(qfitspec), name = "Species")%>%
layout(
updatemenus = list(
list(
type = 'dropdown',
active = 0,
buttons = list(
list(method = "restyle",
args = list("transforms[0].value", unique(iris$Species)[1]),
label = unique(iris$Species)[1]),
list(method = "restyle",
args = list("transforms[0].value", unique(iris$Species)[2]),
label = unique(iris$Species)[2]),
list(method = "restyle",
args = list("transforms[0].value", unique(iris$Species)[3]),
label = unique(iris$Species)[3])
)
)
)
)
Ideally I would have a 4th button called “All” that displayed all the data in the species column and show all the fitted lines in the subset. Thanks