暂时排除绘图中的点

时间:2018-04-24 07:46:08

标签: r shiny plotly r-plotly ggplotly

在下面的plotly示例中(取自here),是否可以引入一个允许用户点击“灰显”的点的函数,因此它将被排除从“活动”数据集中,黄土拟合线会自动调整到新数据集吗?然后可以再次单击这些点以将它们带回“活动”数据集。可能很棘手。正如评论所示,它可能需要shiny,但我无法弄清楚如何。

   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

enter image description here

0 个答案:

没有答案