0

I can morph shapes represented as simple feature geometry ok. I need to do the same thing with the shapes stored as a standard x,y dataframe.

Why does the x,y dataframe method not work for me?

Using Simple Features - Works OK

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

Using x, y dataframe - Morph is broken

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
ixodid
  • 2,180
  • 1
  • 19
  • 46

1 Answers1

0

I think I was looking for:

morph <- tween_polygon(star7, star10,
                     ease = 'linear', 
                     nframes = 12, 
                     id = id)  
ixodid
  • 2,180
  • 1
  • 19
  • 46