使用 gganimate 动画 geom_bar 的问题
Issue with animating geom_bar using gganimate
我在使用 gganimate 时遇到问题,我需要一些帮助。
我正在尝试显示条形图,然后在几年内对其进行动画处理,但我没有输出,也没有显示错误。有错误还是我遗漏了什么?
我正在使用有关欧盟工作事故的数据。
我的 R 版本是:3.6.1 (2019-07-05)
希望下面的代码能说明问题
library(eurostat)
library(rvest)
library(tidyverse)
library(plotly)
library(gganimate)
# get Eurostat data: accidents at work
d_list <- get_eurostat('hsw_ph3_02')
## cast the list into an R data frame
df <- as.data.frame(d_list)
# get data
data_UE27_time <- subset(df, df$wrkenv == "TOTAL" & df$geo =="EU27" &
df$severity =="FAT" & df$sex == "M" & df$age == "TOTAL" &
df$unit == "NR" & df$nace_r2 != "TOTAL" & df$nace_r2 != "A_C-N",
select=c(nace_r2,values,time))
#animated bar plot
gp <- ggplot(data = data_UE27_time, aes(x = nace_r2, y = values))+
geom_bar(stat="identity") +
transition_time(time) +
labs(title = "Year: {frame_time}")
library(dplyr)
library(magick)
library(png)
library(gganimate)
gp <- data_UE27_time %>%
as_tibble() %>%
ggplot(aes(x = nace_r2, y = values, group = time)) +
geom_bar(stat="identity") +
transition_time(time) +
labs(title = "Year: {frame_time}")
animate(gp, nframes = 10)
由 reprex package (v0.3.0)
于 2019-12-02 创建
我在使用 gganimate 时遇到问题,我需要一些帮助。
我正在尝试显示条形图,然后在几年内对其进行动画处理,但我没有输出,也没有显示错误。有错误还是我遗漏了什么?
我正在使用有关欧盟工作事故的数据。 我的 R 版本是:3.6.1 (2019-07-05)
希望下面的代码能说明问题
library(eurostat)
library(rvest)
library(tidyverse)
library(plotly)
library(gganimate)
# get Eurostat data: accidents at work
d_list <- get_eurostat('hsw_ph3_02')
## cast the list into an R data frame
df <- as.data.frame(d_list)
# get data
data_UE27_time <- subset(df, df$wrkenv == "TOTAL" & df$geo =="EU27" &
df$severity =="FAT" & df$sex == "M" & df$age == "TOTAL" &
df$unit == "NR" & df$nace_r2 != "TOTAL" & df$nace_r2 != "A_C-N",
select=c(nace_r2,values,time))
#animated bar plot
gp <- ggplot(data = data_UE27_time, aes(x = nace_r2, y = values))+
geom_bar(stat="identity") +
transition_time(time) +
labs(title = "Year: {frame_time}")
library(dplyr)
library(magick)
library(png)
library(gganimate)
gp <- data_UE27_time %>%
as_tibble() %>%
ggplot(aes(x = nace_r2, y = values, group = time)) +
geom_bar(stat="identity") +
transition_time(time) +
labs(title = "Year: {frame_time}")
animate(gp, nframes = 10)
由 reprex package (v0.3.0)
于 2019-12-02 创建