How to animate a map along the date?

221 Views Asked by At

I have tried by myself but I don't know where is the mistake.

I am trying to animate a Spanish province map with covid19 data. I can plot without any problem the map and the data from a chosen day, but I can't animate all the data along the time period.

This is the .xml file xml file with the data

This is the link to download the shape files: shape files here

and this is my code.

library(tidyverse)    
library(rgdal)     
library(broom)
library(ggplot2)
library(readxl)
library(gganimate)

setwd("C:/Users/...../Provincias_ETRS89_30N")

carto_base <- readOGR("Provincias_ETRS89_30N.shp")
data_provincias <- tidy(carto_base)

dfprovincias <- read_excel("provincias3.xls")
dfprovincias$id <- as.character(dfprovincias$id)
dfprovincias$hospitalized_per_100000 = as.numeric(gsub(",", "\\.",
                                                  dfprovincias$hospitalized_per_100000))
dfprovincias$date <- as.Date(dfprovincias$date, "%y/%m/%d")

dfprovincias_grafico <- data_provincias %>%
  left_join(dfprovincias, by= "id")
dfprovincias_grafico <- na.omit(dfprovincias) 

cols <- RColorBrewer::brewer.pal(8,'Paired')[c(3,6)]

dfprovincias_grafico %>%
  #filter(date == "2020-10-01")%>% 
  ggplot(aes(x=long, y= lat, group = group)) +
  geom_polygon(aes(fill=hospitalized_per_100000), color= "black", size = 0.2) +
  scale_fill_gradient(low=cols[1],high=cols[2]) +
  ggtitle("Hospitalizados por 100.000 habitantes en las provincias de España") +
  transition_reveal(date)
0

There are 0 best solutions below