如何为这个热图制作动画?

时间:2020-07-18 19:12:38

标签: r

我正在查看来自的代码 https://www.kevinzolea.com/post/covid19_nj/tracking-covid19-cases-throughout-nj-with-r/ 制作新泽西州Covid案件的热点图。这是代码:

unzip("County_Boundaries_of_NJ-shp.zip")
NJ_counties <- read_sf("County_Boundaries_of_NJ.shp")
names(NJ_counties)<-tolower(names(NJ_counties))
NJ_counties$county<-tolower(NJ_counties$county)
NJ_covid19$county<-tolower(NJ_covid19$county)
NJ_covid19_shapes<-left_join(NJ_covid19,NJ_counties,by="county")%>%
  dplyr::select(date,county,state,cases,deaths,geometry)
NJ_covid19_shapes<-st_as_sf(NJ_covid19_shapes)
covid_map<-ggplot()+
  geom_sf(data = NJ_counties,fill = "white")+
  geom_sf(data = NJ_covid19_shapes,aes(fill=cases))+
  ggtitle("Spread of COVID-19 Throughout New Jersey")+
  xlab("")+
  ylab("")+
  labs(subtitle = "Date: {current_frame}",
       caption = "Data Source: The New York Times\nAuthor: Kevin Zolea")+
  cowplot::background_grid(major = "none", minor = "none") +
  theme(axis.text.x = element_blank(), axis.ticks.x = element_blank(),
        axis.text.y = element_blank(), axis.ticks.y = element_blank(),
        axis.line = element_blank(),
        legend.background = element_blank(),
        legend.position=c(-0.3,0.8),
        plot.background = element_blank(),
        panel.background = element_blank(),
        legend.text = element_text(size=12),
        legend.title = element_text(colour="black", size=12, face="bold"),
        plot.title=element_text(size=20, face="bold",hjust =0.5),
        plot.subtitle = element_text(hjust = 0.5,size=12),
        plot.caption = element_text(size = 11,
                                    hjust = .5,
                                    color = "black",
                                    face = "bold"))+
  scale_fill_distiller("Number of Positive Cases",
                       palette ="Reds",type = "div",
                       direction = 1)+
  transition_manual(date)

  animate(covid_map, nframe=27,fps = 2, end_pause = 15,height = 500, width =500)

但是,我没有在控制台中输出图形,而是输出图形:

 [1] "./gganim_plot0001.png" "./gganim_plot0002.png" "./gganim_plot0003.png"
 [4] "./gganim_plot0004.png" "./gganim_plot0005.png" "./gganim_plot0006.png"
 [7] "./gganim_plot0007.png" "./gganim_plot0008.png" "./gganim_plot0009.png"
[10] "./gganim_plot0010.png" "./gganim_plot0011.png" "./gganim_plot0012.png"
[13] "./gganim_plot0012.png" "./gganim_plot0012.png" "./gganim_plot0012.png"
[16] "./gganim_plot0012.png" "./gganim_plot0012.png" "./gganim_plot0012.png"
[19] "./gganim_plot0012.png" "./gganim_plot0012.png" "./gganim_plot0012.png"
[22] "./gganim_plot0012.png" "./gganim_plot0012.png" "./gganim_plot0012.png"
[25] "./gganim_plot0012.png" "./gganim_plot0012.png" "./gganim_plot0012.png"
attr(,"frame_vars")

请帮助。

0 个答案:

没有答案