Skip to content

Instantly share code, notes, and snippets.

@thomasp85
Created June 11, 2018 11:23
Show Gist options
  • Save thomasp85/9362bbfae956f2690794abeb2c11cdcc to your computer and use it in GitHub Desktop.
Save thomasp85/9362bbfae956f2690794abeb2c11cdcc to your computer and use it in GitHub Desktop.
Preview of view_zoom
library(ggplot2)
library(gganimate)
library(sf)
earth <- sf::st_as_sf(rnaturalearth::countries110)
views <- data.frame(rbind(
st_bbox(earth[earth$name == 'Denmark',]),
st_bbox(earth[earth$name == 'Australia',])
))
p <- ggplot() +
geom_sf(data = earth, fill = 'white') +
geom_sf(data = earth[earth$name %in% c('Denmark', 'Australia'),], fill = 'forestgreen') +
theme(panel.background = element_rect('lightblue')) +
view_zoom_manual(1, 1, xmin = views$xmin, xmax = views$xmax, ymin = views$ymin, ymax = views$ymax, wrap = TRUE)
animate(p, 100, 10)
@thomasp85
Copy link
Author

gganimate_birth15

@Yoseko
Copy link

Yoseko commented Sep 7, 2018

Thank you for the code!
When I try to reproduce the animation with the same code, however, I always encounter the following error:
Error in params$nframes : $ operator is invalid for atomic vectors
And the problem seems to be in
view_zoom_manual(1, 1, xmin = views$xmin, xmax = views$xmax, ymin = views$ymin, ymax = views$ymax, wrap = TRUE)
Do you have any idea why this happens? Thanks.

@jjhall77
Copy link

Thank you for the code!
When I try to reproduce the animation with the same code, however, I always encounter the following error:
Error in params$nframes : $ operator is invalid for atomic vectors
And the problem seems to be in
view_zoom_manual(1, 1, xmin = views$xmin, xmax = views$xmax, ymin = views$ymin, ymax = views$ymax, wrap = TRUE)
Do you have any idea why this happens? Thanks.

I too have this issue. Anything?

@jsta
Copy link

jsta commented Sep 7, 2021

I had no problems running the code. I'd just add the following line at the end to save the plot anim_save("test.gif")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment