停止错误("animation of ",class(绘图)[1],“不支持的对象”):缺少参数 "plot",没有默认值
Error in stop("animation of ", class(plot)[1], " objects not supported") : argument "plot" is missing, with no default
我想为每个国家/地区在过去 3 年中的能源生产制作条形动画。写了下面的代码,但我收到一个错误。
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"))
谁能帮我解决这个问题?
可能有几种方法可以修复它。这适用于我的机器:
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())
我想为每个国家/地区在过去 3 年中的能源生产制作条形动画。写了下面的代码,但我收到一个错误。
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"))
谁能帮我解决这个问题?
可能有几种方法可以修复它。这适用于我的机器:
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())