Skip to content

Using {tidyterra} with {gganimate} #157

Answered by frzambra
frzambra asked this question in Q&A
Discussion options

You must be logged in to vote

It can! I share a simple script if it could help anyone.

library(gganimate)
library(tidyterra)
library(geodata)
library(ggplot2)
library(rnaturalearth)

temp <- geodata::worldclim_country('chile','tavg',path = tempdir())

chl <- ne_countries(country = 'chile',scale ='medium',returnclass = 'sf')

chl_mod <- chl |> st_geometry() |>  st_cast('POLYGON')
chl_cont <- chl_mod[-(1:2)] 

temp_m <- crop(temp,chl_cont)
temp_m <- mask(temp_m,vect(chl_cont))

map_temp <- ggplot() +
  geom_spatraster(data = temp_m) +
  scale_fill_gradientn(colors = viridis::inferno(30),na.value = 'transparent') +
  labs(x = "", y = "") +
  transition_manual(lyr) +
  theme_bw()

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by dieghernan
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
📊 ggplot2 Issues related with the implementation of ggplot2 functionalities ❔ q&a Questions on the usage of tidyterra
2 participants
Converted from issue

This discussion was converted from issue #156 on December 06, 2024 17:42.