停止错误“动画”,类图[1],“不支持的对象”:参数“图”丢失,没有默认值

问题描述

我想为每个下乡的酒吧制作动画,以使其在过去三年中产生能量。编写了以下代码,但出现错误

library(gganimate)
library(ggplot2)

ggplot(energyProd_distribution,aes(country_name,ggwt_hours,color=country_name,fill = country_name))+
  geom_bar(stat = "identity")+
  scale_y_continuous(labels = scales::comma)+
  labs(x = "Year",y="Energy Production(GWh)",title = "Analysis of the Energy Production between 2016 to 2018",fill = "Year",color = "Year")+
  theme(plot.title = element_text(hjust = 0.5))+
  theme_minimal()+
  theme(legend.position="top")+
  transition_states(year)+
  animate(renderer = gifski_renderer())

Error in stop("animation of ",class(plot)[1]," objects not supported") : 
  argument "plot" is missing,with no default

    > dput(head(energyProd_distribution))
structure(list(country = c("DE","DE","FR","FR"
),country_name = c("Germany","Germany","France","France"),year = c("2016","2017","2018","2016","2018"),ggwt_hours = c(619606,624969,578460.796,545060.548,542597.798,560767.871)),row.names = c(NA,-6L),groups = structure(list(
    country = c("DE","FR"),.rows = structure(list(1:3,4:6),ptype = integer(0),class = c("vctrs_list_of","vctrs_vctr","list"))),row.names = 1:2,class = c("tbl_df","tbl","data.frame"),.drop = TRUE),class = c("grouped_df","tbl_df","data.frame"))

有人可以帮助我解决问题吗?

解决方法

可能有几种方法可以修复它。这适用于我的机器:

library(gganimate)
library(ggplot2)

gr <- ggplot(energyProd_Distribution,aes(country_name,ggwt_hours,color = country_name,fill = country_name)) +
  geom_bar(stat = "identity") +
  scale_y_continuous(labels = scales::comma) +
  labs(
    x = "Year",y = "Energy Production(GWh)",title = "Analysis of the Energy Production between 2016 to 2018",fill = "Year",color = "Year"
  ) +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme_minimal() +
  theme(legend.position = "top") +
  transition_states(year) 

animate(gr,renderer = gifski_renderer())

enter image description here

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...