Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(openair)
- library(tidyverse)
- library(lubridate)
- library(gganimate)
- jhn <- as_tibble(importSAQN(site = "REN02", year = 2017:2019, pollutant = "all")) %>%
- mutate(day = date(date))
- # saveRDS(jhn, "jhn.rds")
- # jhn <- readRDS("jhn.rds")
- pm2.5_size = 1.5 # smallest dot size
- p <- jhn %>%
- # filter(date >= dmy("01-01-2019"), date < dmy("01-02-2019")) %>%
- ggplot(aes(x = date)) +
- ylim(0, 100) +
- ylab("") +
- xlab("") +
- scale_x_datetime(date_breaks = "1 day", breaks = NULL) + # this and view_follow fix the range
- labs(title = "{format(frame_time, '%B %d %Y')}") +
- geom_smooth(colour="black", alpha = 1, aes(y = pm10)) +
- geom_smooth(colour="blue", alpha = 1, aes(y = pm2.5)) +
- geom_point(colour="black", alpha = .3, aes(y = pm10), size = 4*pm2.5_size) +
- geom_point(colour="blue", alpha = .3, aes(y = pm2.5), size = pm2.5_size) +
- theme_minimal() +
- theme(axis.text.x = element_blank(), panel.grid.major.x = element_blank(), panel.grid.minor.x = element_blank()) +
- # gganimate
- transition_time(day) +
- enter_fade() +
- exit_fade() +
- ease_aes("linear") +
- view_follow(fixed_y = TRUE)
- # output as animated gif
- scale = .5
- animate(p, width = 1920*scale, height = 1080*scale,
- fps = 24, duration = 60)
- anim_save("anim.gif")
- # output as video
- scale = 1
- animate(p, width = 1920*scale, height = 1080*scale,
- fps = 24, duration = 60, renderer = ffmpeg_renderer())
- anim_save("anim.mp4")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement