【发布时间】:2019-12-02 22:16:23
【问题描述】:
我可以在 R 中生成一些看起来不错的等值线图,例如以下内容
library(tidyverse)
library(rnaturalearth)
library(rnaturalearthdata)
set.seed(1234)
ww <- ne_countries(scale = "medium", returnclass = "sf")
ll <- ww$name %>% length
val <- sample(c("a","b","c","d"), ll, replace=T)
bb <- ne_download(type = "wgs84_bounding_box", category = "physical",
returnclass = "sf")
ww <- ww %>% mutate(value=val)
gpl1 <- ggplot(data = ww) +
geom_sf(aes(fill=value), col = "black", lwd = 0.3 )+
xlab(NULL) + ylab(NULL) +
ggtitle("World Export of Merchandise")+
geom_sf(data = bb, col = "grey", fill = "transparent") +
theme(plot.background = element_rect(fill = "white"),
panel.background = element_rect(fill = 'white'),
panel.grid.major = element_line(colour = "grey"),
legend.position="top",
plot.title = element_text(lineheight=.8, size=24, face="bold",
vjust=1),
legend.text = element_text(vjust=.4,lineheight=1,size = 14),
legend.title = element_text(vjust=1,lineheight=1, size=14,
face="bold" ))+
coord_sf(crs = "+proj=eqearth +wktext")
ggsave("test_world1.pdf", gpl1, width=6*1.618,height=5)
但是假设我有几年的数据,例如
values_years <- tibble(value=sample(c("a","b","c","d"), 4*ll, replace=T),
years=sample(seq(4), 4*ll, replace=T))
有谁知道如何使用 gganimate 生成一个等值线地图,其中国家颜色会在显示不同年份的同时自动改变? 我不是在寻找交互式可视化,而是在寻找类似的东西
https://www.blog.cultureofinsight.com/2017/09/animated-choropleth-maps-in-r/
只是我很难根据自己的需要简化该示例。 任何帮助表示赞赏!
【问题讨论】: