0

I want to show the date in a map with " transition_manual " from gganimate but I don´t know how to do it. I have upload the gif map here: map with gganimate

I have uploaded the .xlm here: xml data

and my code is here:

    # para manipular dataframes
library(tidyverse)
# para importar archivos shapefiles
library(rgdal)
# Para transformar los archivos shapefiles 
library(broom)
library(ggplot2)
library(readxl)
library(gganimate)

library(sf)



setwd("C:/Users/blackmamba/Desktop/mapas/Provincias_ETRS89_30N")

carto_base <- readOGR("Provincias_ETRS89_30N.shp")
#plot(carto_base) para verificar el directorio y demas

# Para convertir el archivo shapefile en un dataframe utilizamos la función tidy()
data_provincias <- tidy(carto_base)



dfprovincias <- read_excel("incidencia.xls")
#view(dfprovincias)

#leemos los números de la columna ID como carácteres, para poder juntarlos con lef_joint al archivo que contine las id cartograficas 
dfprovincias$id <- as.character(dfprovincias$id)
dfprovincias$incidencia = as.numeric(gsub(",","\\.",dfprovincias$incidencia))


dfprovincias$fecha<-as.Date(dfprovincias$fecha, "%Y-%m-%d")
#str(dfprovincias$fecha)




dfprovincias_grafico1 <- data_provincias%>%
  left_join(dfprovincias, by= "id")





head(dfprovincias_grafico1)





colores <- RColorBrewer::brewer.pal(9,'Reds')[c(2,3,4,5,6,7,8,9)]

# En función de los resultados obtenidos establecemos nuestros cortes en los siguientes valores:
corte <- c( 0,15,30,50,80,100,150,250,860)


# Los valores mínimo y máximo son:

val_min <- min(dfprovincias_grafico1$incidencia)
val_max <- max(dfprovincias_grafico1$incidencia)


# Y por tanto, los rangos serán los siguientes:

breaks <- c(val_min, corte, val_max)

dfprovincias_grafico1$breaks <- cut(dfprovincias_grafico1$incidencia,
                                   breaks = breaks,
                                   include.lowest = T)

breaks_scale <- levels(dfprovincias_grafico1$breaks)
labels_scale <- rev(breaks_scale)





dfprovincias_grafico1 %>%
  #filter (fecha=="2020-09-25")%>%
  ggplot(aes(x=long, y= lat, group = group)) +
  geom_polygon(aes(fill=breaks), color= "white", size = 0.2) +
  labs( #title = "Tasa de INCIDENCIA/100.000 hab por provincias",
        #title ="Fecha: {as.Date.numeric(frame_along, origin = '2020-10-01')}"
        subtitle = "desde 15 de Junio al 5 de Ocutbre 2020) ",
        caption = "Fuente: ISCIII",
        fill = "incidencia por 100.000 hab") +
  theme_minimal() +
  theme(
    axis.line = element_blank(),
    axis.text = element_blank(),
    axis.title = element_blank(),
    axis.ticks = element_blank(),
    plot.background = element_rect(fill = "snow", color = NA),
    panel.background = element_rect(fill= "snow", color = NA),
    plot.title = element_text(size = 16, hjust = 0),
    plot.subtitle = element_text(size = 12, hjust = 0),
    plot.caption = element_text(size = 8, hjust = 1),
    legend.title = element_text(color = "grey40", size = 13),
    legend.text = element_text(color = "grey40", size = 12, hjust = 0),
    legend.position = c(0.93, 0.3),
    plot.margin = unit(c(0.5,2,0.5,1), "cm")) +
  scale_fill_manual(
    values = rev(colores),
    breaks = rev(breaks_scale)) +
#transition_states(fecha) 
transition_manual(fecha)+
  labs(title = "Day = {frame}") 

The date var its called "fecha"

I want to slow the .gif too. It´s possible? I don´t know how to do it neither. Thank`s you all in advance fellas!

Raul
  • 139
  • 9
  • Take a look at the *minimal* part of the [mcve] guidance: if `dfprovincias_grafico1` is the data we need in order to recreate the problem, just give us a sample of that and skip posting all the code that creates it. That would save us dozens of lines of code that possibly also need debugging, and helps you narrow down the problem as well. Same goes for the 15 lines of code related to customizing the theme: if the question isn't about theming, we don't need it right now. – camille Oct 08 '20 at 14:02
  • 2
    Beyond that, it doesn't seem like the gif you've posted is what actually comes from the code, since the title in the gif matches the title setting you've commented out. What are you *actually* getting as a title from this code, where you'd expect something matching `"Day = {frame}"`? – camille Oct 08 '20 at 14:05
  • yes. I want to show in the title the date. You know how to? – Raul Oct 08 '20 at 14:48
  • Possibly. It seems like your code should, but the gif you posted doesn't match the code you posted, so I'm not sure why it wouldn't. And I'd really rather get a sample the data directly from the post instead of downloading from a cloud drive—lots of examples on how to post data [here](https://stackoverflow.com/q/5963269/5325862) – camille Oct 08 '20 at 14:56

0 Answers0