I want to animate the bars of each cuntry for their energy production through out the 3 years. Wrote the below code but I am getting an error.
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", "DE", "FR", "FR", "FR"
), country_name = c("Germany", "Germany", "Germany", "France",
"France", "France"), year = c("2016", "2017", "2018", "2016",
"2017", "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", "tbl", "data.frame"))
Can anyone help me to resolve the issue?
There might be several ways to fix it. This works on my machine: