-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimate-monthly-map.r
39 lines (30 loc) · 1 KB
/
animate-monthly-map.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
# script can be executed with
library(readr)
library(ggplot2)
library(dplyr)
library(lubridate)
library(gganimate)
temps = read_csv("saxony-monthly-temperature.csv")
temp_median_year = temps %>%
mutate(yr= as.integer(year(ymd(MESS_DATUM_BEGINN))), mo= month(ymd(MESS_DATUM_BEGINN))) %>%
filter(mo == 2)%>%
group_by(yr,STATIONS_ID)
nyears = length(unique(temp_median_year$yr))
message("animating ",nyears," years")
# https://github.com/thomasp85/gganimate
anplot = ggplot(temp_median_year,aes(x=geo_lon,y=geo_lat,color=MO_TT)) +
geom_point(size=6) +
theme_minimal() +
xlab("longitude") +
ylab("latitude") +
labs(title = 'Year: {frame_time}', x = 'longitude', y = 'latitude') +
transition_time(yr) +
ease_aes('linear')
anim = animate(anplot,
nframes=nyears,
fps=15,
renderer = gifski_renderer(),
width=500,
height=350)
#magick::image_write(anim, path="monthly-temperatures.gif")
anim_save("monthly-temperatures-map.gif",anim)