使用库(tweenr)补间圆圈以使用xy数据帧加星号

时间:2019-02-25 03:33:32

标签: r ggplot2 gganimate

我可以使表示为简单要素几何的形状变形。我需要对存储为标准x,y数据框的形状执行相同的操作。

为什么x,y数据框方法对我不起作用?

使用简单功能-可以正常运行

library(tidyverse)
library(gganimate)
library(transformr)

star1 <- sf::st_sfc(poly_star(n = 7, st = TRUE))
circle1 <- sf::st_sfc(poly_circle(st = TRUE))

df1 <- data.frame(
  id = c(1),
  geo = c(star1)
)

df2 <- data.frame(
  id = c(1),
  geo = c(circle1)
)

morph <- tween_sf(df1, df2,
                  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

使用x,y数据框-变形已损坏

library(tidyverse)
library(gganimate)
library(transformr)
library(tweenr)


star7 <- poly_star(n = 7, st = FALSE)

star10 <- poly_star(n = 10, st = FALSE)

morph <- tween_state(star7, star10,
                     ease = 'linear', 
                     nframes = 12, 
                     id = id)  

ani <- ggplot(morph) +
  geom_polygon(aes(x = x, y = y, group = id)) +
  transition_time(time = .frame) +
  theme(legend.position = "none") 

show <- animate(ani, nframes = 30, fps = 30, 
                renderer = gifski_renderer(loop = FALSE), start_pause = 15)

show

1 个答案:

答案 0 :(得分:0)

我想找的是

morph <- tween_polygon(star7, star10,
                     ease = 'linear', 
                     nframes = 12, 
                     id = id)