如何用gganimate上的transition_manual修改gif的标题?

时间:2019-04-15 14:35:19

标签: r ggmap gganimate

我想用murder$mes的名称来更改标题的名称,我尝试使用transition_time,但这是行不通的。 仅适用于transition_manual 这是代码(可复制)

library(ggmap)
library(sp)

murder <- subset(crime, offense == "murder")
murder$mes <- as.yearmon(substr(murder$time,1,7))
murder <- SpatialPointsDataFrame(murder[,c("lon", "lat")], data=murder,
                                 proj4string = CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"))

p <- ggmap(get_stamenmap(bbox=c(left=min(murder$lon), bottom=min(murder$lat),
                                right=max(murder$lon), top=max(murder$lat)), zoom=10))


murder$hour <- cut(murder$hour, 
                   breaks = c(0, 2, 4, 8, 12, 16, 20, 23, 25), 
                   labels = c("00:00", "02:00", "04:00", "08:00", 
                              "12:00", "16:00", "20:00", "23:00"),
                   right = FALSE)

mapa <- p +
    geom_point(data = murder@data,
               aes(x = lon, y = lat, color = hour)) +
    scale_color_viridis_d(option = "C",name = "Hour",drop = FALSE,
                          guide = guide_legend(keyheight = unit(3, units = "mm"), 
                                               keywidth = unit(6, units = "mm"),
                                               label.position = "bottom", 
                                               title.position = 'top', 
                                               nrow = 1,
                                               label.theme = element_text(size = 6, face = "bold",
                                                                          color = "grey2",
                                                                          family = "Gotham"),
                                               title.theme = element_text(size = 6, face = "bold",
                                                                          color = "grey2",
                                                                          family = "Gotham", 
                                                                          hjust=0.5)))+
    transition_manual(mes)+
    labs(title = "Month = {frame}") 

mapa

这是代码的结果:

我想要月= ene。 2010(取决于月份)。 谢谢!

0 个答案:

没有答案