-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathveintisiete.R
50 lines (35 loc) · 1.68 KB
/
veintisiete.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# #30díasdegráficos día 27
# Visualización animación temperaturas enero en Santiago
# https://lpdaac.usgs.gov/products/mod11a1v006/
# Autora: Stephanie Orellana (@sporella)
# Cargar librerías --------------------------------------------------------
library(raster)
library(tidyverse)
library(sf)
library(gganimate)
# Cargar raster y convertir unidades --------------------------------------
lst <- raster("data/lst_01.tif")
lst <- (lst * 0.02) - 273.15
# Leer comunas ------------------------------------------------------------
comunas <- st_read("data/comunas_rm.shp")
# Hacer estadística zonal -------------------------------------------------
mean_ene <- comunas %>%
dplyr::select(Comuna, Region, Provincia) %>%
mutate(ene = raster::extract(lst$lst_01, comunas["Comuna"], fun = mean, na.rm =
T)) %>%
dplyr::arrange(desc(ene))
# Hacer gráfico -----------------------------------------------------------
p <- ggplot() +
geom_sf(data = mean_ene, aes(fill = ene), colour = "grey33", show.legend = F) +
scale_fill_viridis_c(option = "C",
breaks = seq(30, 42, 1),
guide = "legend") +
labs(caption = "@sporella", subtitle = "Temperatura superficial mes de enero, sensor MODIS (MOD11A1)")+
theme_minimal() +
theme(plot.title = element_text(size=15, face="bold"))+
coord_sf()+
ggtitle(paste("{current_frame}:", "{round(mean_ene$ene[mean_ene$Comuna == current_frame],2)}", "[°C]")) +
transition_manual(factor(Comuna, levels = unique(mean_ene$Comuna)), cumulative = T)+
view_follow()
p2 <- animate(p, fps = 2, start_pause = 1)
anim_save(filename = "plots/veintisiete/temp_ene.gif", animation = p2)