为什么动画图比静态图小?

问题描述 投票:0回答:1

下面的代码将星形变成圆形。如果我只是绘制星星的大小是伟大的。

ggplot(star1) +
  geom_sf(aes(geometry = geometry))

static star

但是,动画最终变小了:

animated star如何让动画与星星的静态情节大小相同?

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
r ggplot2 gganimate
1个回答
0
投票

输出动画大小的宽度和高度参数(以像素为单位)是动画的选项

animate(ani, nframes = 30, fps = 30, width = 900, 
          renderer = gifski_renderer(loop = FALSE), start_pause = 15)
© www.soinside.com 2019 - 2024. All rights reserved.