具有自定义步骤标签的动画滑块

时间:2019-08-14 18:46:05

标签: r animation plotly r-plotly

是否可以使用自定义步骤标签创建动画滑块?

默认情况下,步骤标签由plot_ly(frames=X)参数定义。但是,frames列表然后被排序。

如何控制动画滑块的显示标签?

plotly网站上的an example显示了如何使用

控制标准滑块的标签
%>% layout(sliders = list(
      list(
        steps = list(
          list(args = list(), 
               label = "Red", 
               value = "1"
          ),
          list(args = list(), 
               label = "Green", 
               value = "2"
          ),
          list(args = list(), 
               label = "Blue", 
               value = "3"
          )
        ))))

但是我看不出如何使它成功适应animation_slider()。我尝试过

%>% animation_slider(steps = [...])

但无济于事:frame参数仍在使用。这是我尝试的完整MRE:

library(plotly)

df <- data.frame(x = c("1", "2", "3"), 
                 y = c("1", "1", "1"),
                 frames = c(1, 2, 3))
p <- df %>%
  plot_ly(x = ~x, y = ~y, frame = ~frames,
          mode = "markers", 
          marker = list(size = 20,
                        color = 'green'), 
          type = "scatter") %>%
  animation_slider(
    steps = list(
      list(args = list(), 
           label = "4Q2018", 
           value = 1
      ),
      list(args = list(), 
        label = "1Q2019", 
        value = 2
      ),
      list(args = list(), 
        label = "2Q2019", 
        value = 3
      )
    ))

p

0 个答案:

没有答案