问题
In the following plotly
example (taken from here), is it possible to introduce a function that allows the user to click on a point to 'grey it out', so it would be excluded from the 'active' dataset, and the loess fit line would automatically adjust to the new dataset? The point(s) could then be clicked again to bring them back into the 'active' data set. Could be tricky. As the comments suggest it will likely require shiny
, but I’m having trouble figuring out how.
library(plotly)
library(broom)
m <- loess(mpg ~ disp, data = mtcars)
p <- plot_ly(mtcars, x = ~disp, color = I("black")) %>%
add_markers(y = ~mpg, text = rownames(mtcars), showlegend = FALSE) %>%
add_lines(y = ~fitted(loess(mpg ~ disp)),
line = list(color = 'rgba(7, 164, 181, 1)'),
name = "Loess Smoother") %>%
add_ribbons(data = augment(m),
ymin = ~.fitted - 1.96 * .se.fit,
ymax = ~.fitted + 1.96 * .se.fit,
line = list(color = 'rgba(7, 164, 181, 0.05)'),
fillcolor = 'rgba(7, 164, 181, 0.2)',
name = "Standard Error") %>%
layout(xaxis = list(title = 'Displacement (cu.in.)'),
yaxis = list(title = 'Miles/(US) gallon'),
legend = list(x = 0.80, y = 0.90))
# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = api_create(p, filename="multiple-loess-se")
chart_link
来源:https://stackoverflow.com/questions/49996086/temporarily-exclude-points-in-plotly-graph