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)
@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