R 阴谋策划没有出现

R 阴谋策划没有出现,r,plotly,R,Plotly,我正在尝试设置此测试的动画data.frame,但是plotly绘图甚至没有显示!同样的代码也适用于原始plotly数据。我仔细检查了列的类,它们与示例相同。我现在不明白为什么这样做失败了 这也适用于标记模式,但不适用于行模式 total <- data.frame(replicate(4,sample(0:1, 100, rep=TRUE))) names(total) <- c("date", "frame", "P1.10", "year") total$date <-

我正在尝试设置此测试的动画
data.frame
,但是
plotly
绘图甚至没有显示!同样的代码也适用于原始
plotly
数据。我仔细检查了
列的
,它们与
示例相同。我现在不明白为什么这样做失败了

这也适用于
标记
模式,但不适用于
模式

total <- data.frame(replicate(4,sample(0:1, 100, rep=TRUE)))
names(total) <- c("date", "frame", "P1.10", "year")
total$date <- as.numeric(as.character(t(rbind(runif(100, min=2000, max=2010)))))
f.rank <- order(total$date)
total$frame[f.rank] <- 1:nrow(total)
total$P1.10 <- as.numeric(as.character(t(rbind(runif(100, min=1, max=10)))))
total$year <- 2000



p <- total %>%
  plot_ly(
    x = ~date, 
    y = ~P1.10,
    frame = ~frame, 
    type = 'scatter',
    mode = 'lines', 
    line = list(simplyfy = F)
  ) %>% 
  layout(
    xaxis = list(
      title = "Date",
      zeroline = F
    ),
    yaxis = list(
      title = "P1.10",
      zeroline = F
    )
  ) %>% 
  animation_opts(
    frame = 100, 
    transition = 0, 
    redraw = FALSE
  ) %>%
  animation_slider(
    hide = T
  ) %>%
  animation_button(
    x = 1, xanchor = "right", y = 0, yanchor = "bottom"
  )

total您在示例中忽略了
acculate\u by
。您还需要一个
ID
字段。这是相同的,但结合使用
ggplot

set.seed(123)
library(plotly)

total <- data.frame(replicate(4,sample(0:1, 100, rep=TRUE)))
names(total) <- c("date", "frame", "P1.10", "year")
total$date <- as.numeric(as.character(t(rbind(runif(100, min=2000, max=2010)))))
f.rank <- order(total$date)
total$frame[f.rank] <- 1:nrow(total)
total$ID[f.rank] <- 1:nrow(total)
total$P1.10 <- as.numeric(as.character(t(rbind(runif(100, min=1, max=10)))))
total$year <- 2000

accumulate_by <- function(dat, var) {
  var <- lazyeval::f_eval(var, dat)
  lvls <- plotly:::getLevels(var)
  dats <- lapply(seq_along(lvls), function(x) {
    cbind(dat[var %in% lvls[seq(1, x)], ], frame = lvls[[x]])
  })
  dplyr::bind_rows(dats)
}

total <- total %>%
  accumulate_by(~ID)

p <- ggplot(total,aes(ID, P1.10, frame = frame)) +
  geom_line()

p <- ggplotly(p) %>%
  layout(
    title = "",
    yaxis = list(
      title = "P1.10",
      zeroline = F,
      tickprefix = "$"
    ),
    xaxis = list(
      title = "Date",
      zeroline = F, 
      showgrid = F
    )
  ) %>% 
  animation_opts(
    frame = 100, 
    transition = 0, 
    redraw = FALSE
  ) %>%
  animation_slider(
    currentvalue = list(
      prefix = "Day "
    )
  )
set.seed(123)
图书馆(绘本)
全部的