问题描述
我想为每个下乡的酒吧制作动画,以使其在过去三年中产生能量。编写了以下代码,但出现错误。
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())