-
Dear all, is it possible to use {tidyterra} with {gganimate}, for example, to animate raster time series? Any example to follow? |
Beta Was this translation helpful? Give feedback.
Answered by
frzambra
Dec 6, 2024
Replies: 2 comments
-
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() |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
dieghernan
-
Cool! I added this example to the FAQ article https://dieghernan.github.io/tidyterra/articles/faqs.html#gganimate |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It can! I share a simple script if it could help anyone.