下面的代码将星星变形为圆形。如果我只画星星,那大小就很大。
ggplot(star1) +
geom_sf(aes(geometry = geometry))
但是,动画最终变小了:
library(tidyverse)
library(gganimate)
library(transformr)
star1 <- sf::st_sfc(poly_star(n = 7, st = TRUE))
circle1 <- sf::st_sfc(poly_circle(st = TRUE))
star2 <- star1 + c(2, 0)
circle2 <- circle1 + c(2,0)
star1 <- data.frame(
id = c(1, 2),
geo = c(star1, star2)
)
circle2 <- data.frame(
id = c(1, 2),
geo = c(circle1, circle2)
)
morph <- tween_sf(star1, circle2,
ease = 'linear',
nframes = 12,
id = id)
ani <- ggplot(morph) +
geom_sf(aes(geometry = geometry)) +
transition_time(time = .frame) +
theme(legend.position = "none")
show <- animate(ani, nframes = 30, fps = 30,
renderer = gifski_renderer(loop = FALSE), start_pause = 15)
show
答案 0 :(得分:0)
用于输出动画大小的宽度和高度参数(以像素为单位)是可设置动画的选项
animate(ani, nframes = 30, fps = 30, width = 900,
renderer = gifski_renderer(loop = FALSE), start_pause = 15)