代码之家  ›  专栏  ›  技术社区  ›  jjmerelo

“错误:提供的文件不存在”当使用gganimate with line时

  •  0
  • jjmerelo  · 技术社区  · 6 年前

    作为后续行动 this question ,我尝试了,正如 a comment ,使用 geom_line transition_reveal . 因为使用了几个 几何线

    library(ggplot2)
    library(transformr)
    library(gifski)
    library(gganimate)
    library(tidyr)
    
    load("covid-19-es.Rda")
    data <- gather(data,Tipo,Cuantos,c(casos,salidas))
    my_plot <- ggplot(data,aes(x = Fecha, y = Cuantos, group= Tipo, color=Tipo)) + 
      geom_line() +
      transition_reveal(Fecha) + ease_aes("linear")+
      labs(title='Day: {closest_state}')
    
    animate(
      plot = my_plot,
      render = gifski_renderer(),
      height = 600,
      width = 800, 
      duration = 10,
      fps = 20)
    
    anim_save('gifs/casos-salidas-linea.gif')
    

    使用的数据文件是 here

    Error: Provided file does not exist
    

    ggplot2 . 如果有别的方法,那就很好了

    使用的版本

    • 3.6兰特
    • GG2图3.3.0
    • GG1.0.5动画
    • 吉夫斯基0.8.6
    0 回复  |  直到 6 年前
        1
  •  4
  •   paqmo    6 年前

    您想要的标签变量是 {frame_along} ,所以: labs(title='Day: {frame_along}') . 从参考手册中现在还不太清楚(也不清楚错误消息),但是包含一个不熟悉的label变量似乎会提示这些错误。 {closest_state} 搭配 transition_states() .

    library(tidyverse)
    library(gganimate)
    
    load("covid-19-es.Rda")
    
    data <- gather(data,Tipo,Cuantos,c(casos,salidas))
    
    ggplot(data,aes(x = Fecha, y = Cuantos, color=Tipo)) + 
      geom_line() +
      transition_reveal(Fecha) + 
      ease_aes("linear") +
      labs(title='Day: {frame_along}')
    

    于2020-03-28由 reprex package (第0.3.0版)

    推荐文章