将 gganimate 与行一起使用时出现“错误:提供的文件不存在”

jjm*_*elo 1 r ggplot2 gganimate

作为这个问题的后续,我尝试按照评论的建议使用geom_lineand transition_reveal。由于使用多个geom_line语句似乎与 gganimate 发生冲突(发出有关在组中使用单个元素而不渲染任何内容的警告),因此我尝试将所有内容收集到单个列和单个 ggplot2 语句中。

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')
Run Code Online (Sandbox Code Playgroud)

使用的数据文件在这里。我在使用 animate 时收到很多警告,但它最终被无用的消息杀死(再次):

Error: Provided file does not exist
Run Code Online (Sandbox Code Playgroud)

归根结底,我需要的是使用 制作折线图动画ggplot2。如果还有其他方法的话,非常欢迎

使用的版本

  • 3.6
  • ggplot 2_3.3.0
  • 动画1.0.5
  • gifski 0.8.6

paq*_*qmo 5

您想要的标签变量是{frame_along},因此:labs(title='Day: {frame_along}')。目前的参考手册(也不是错误消息)还不是很清楚,但包含不熟悉的标签变量似乎会提示这些错误。{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}')
Run Code Online (Sandbox Code Playgroud)

由reprex 包(v0.3.0)于 2020-03-28 创建