0

I want change the title´s name with the names of the murder$mes, I try with transition_time but it is not works. It´s only works with transition_manual This is the code (reproducible)

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

This is the result of the code:

I want Month= ene. 2010 (depends of the month). Thank you!

  • The package vignette shows how to use `glue` syntax to set the title – camille Apr 15 '19 at 14:59
  • 1
    Here's a similar question: https://stackoverflow.com/q/37397303/5325862. Is the issue that you're trying to show the name of the month instead of the number of the month? e.g. ene., feb., mar. instead of 1, 2, 3 – camille Apr 15 '19 at 15:01
  • see if this answers. It is a bit unclear to me what you are asking, just a wild guess that my solution with manipulation `labs` would work for you. https://stackoverflow.com/questions/56411936/display-different-time-elements-at-different-speeds-in-gganimate – M-- Jun 04 '19 at 20:03

0 Answers0