1

在以下plotly示例中(取自此处),是否可以引入一个功能,允许用户单击一个点以“将其变灰”,因此它将被排除在“活动”数据集中,并且黄土拟合线会自动适应新的数据集吗?然后可以再次单击这些点以将它们带回“活动”数据集中。可能很棘手。正如评论所暗示的那样,它可能需要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

在此处输入图像描述

4

0 回答 0