廢話不多說,直接附上code
影片含有程式碼詳細解說,若有誤再煩請告知,謝謝
library(gapminder)
library(gganimate)
library(gifski)
library(dplyr)
data(gapminder)
gif <- gapminder %>%
ggplot(aes(gdpPercap, lifeExp, size = pop, colour = country)) +
geom_point(alpha = 0.7,show.legend = FALSE) + #透明度
scale_colour_manual(values = country_colors) +
scale_size(range = c(2, 12)) +
scale_x_log10() +
# new
labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
transition_time(year) + #時間間隔,range = c(10L, 20L)
ease_aes('linear') #呈現效果
animate(gif, duration = 5, fps = 20,
width = 500, height = 300)
#duration 動畫持續時間 fps每秒跳幾張
anim_save("D:\\output.gif")