我想绘制带有R和gganimate的动画Chorophlet贴图。我需要显示更改类别的区域,而不是显示从一个地方移动到另一个地方的多边形。
library(sf)
library(tidyverse)
library(gganimate)
nc <- st_read(system.file("shape/nc.shp", package="sf"))
nc <- nc %>% filter(CNTY_ID %in% c(1825:1830))
nc_data <- tribble(~CNTY_ID,~year,~value,
1825,2000,1,
1825,2001,2,
1825,2002,3,
1827,2000,3,
1827,2001,4,
1827,2002,1,
1828,2000,2,
1828,2001,1,
1828,2002,4)
nc <- nc %>% full_join(nc_data,by="CNTY_ID")
nc <- nc %>% mutate(value= as.factor(value) )
p <- nc %>%
ggplot() +
geom_sf(aes(fill=value), color="black",lwd=.2) +
transition_time(year)
animate(p,nframe=6)
# same movements with
p <- nc %>%
ggplot() +
geom_sf(aes(fill=value), color="black",lwd=.2) +
transition_states(year)
animate(p,nframe=27)
预期结果将是多边形改变颜色...不移动。
答案 0 :(得分:0)
好的,我想我已经找到了答案:
transition_manual(year)