代码拉取完成,页面将自动刷新
library(haven)
library(tidyverse)
library(gganimate)
library(ggthemes)
library(ggfortify)
data <- read_dta("D:/github/forecast/data/data_0224.dta")
aqi<- data %>%
mutate(year = as.character(year),month = as.character(month),
day = as.character(day)) %>%
filter(year == 2020) %>%
mutate(month = str_pad(month,width = 2,pad = 0,side='left'),day = str_pad(day,width = 2,pad=0,side = 'left')) %>%
mutate(date = str_c(year,month,day,sep = '-')) %>%
select(-year,-month,-day) %>%
select(aqi,pm25,so2,no2,o3,co,city,date) %>%
drop_na() %>%
mutate(date = as.Date(date)) %>%
filter (city %in% c("成都",'海口','武汉'))
plot<-ggplot(aqi,mapping = aes(x=date,y=aqi,color=city)) +geom_line(size=1.3,alpha=0.6)+theme_clean()+
ggtitle('三个城市2020年aqi数据') +xlab('时间')+ylab('空气质量')+
transition_reveal(date)
animate(plot,
nframes = 200,
fps = 30)
anim_save('aqi.gif',path = 'D:/github/forecast/image')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。