Temporarily exclude points in plotly graph

徘徊边缘 提交于 2019-12-24 06:07:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!