问题描述
我想用gganimate中的“ transition_manual”在地图上显示日期,但我不知道该怎么做。我已经在此处上传了gif地图:
# 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",plot.title = element_text(size = 16,hjust = 0),plot.subtitle = element_text(size = 12,plot.caption = element_text(size = 8,hjust = 1),legend.title = element_text(color = "grey40",size = 13),legend.text = element_text(color = "grey40",size = 12,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}")
日期变量称为“ fecha”
我也想减慢.gif的速度。这是可能的?我也不知道该怎么办。 谢谢大家,伙计们!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)