【问题标题】:How to fix the movements of the polygons?如何修复多边形的运动?
【发布时间】:2019-08-28 22:17:39
【问题描述】:

我想用 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)

预期的结果将是多边形改变颜色...而不移动。

【问题讨论】:

    标签: r sf gganimate


    【解决方案1】:

    好的,我想我找到了答案:

    transition_manual(year)
    

    【讨论】:

    • 非常感谢!这几天我一直在努力解决这个问题!!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-17
    • 1970-01-01
    • 2014-02-02
    • 1970-01-01
    相关资源
    最近更新 更多