【问题标题】:Animated map using geom_sf and ggplotly使用 geom_sf 和 ggplotly 的动画地图
【发布时间】:2021-05-24 19:54:35
【问题描述】:

你会在GitHub找到这个问题的副本。

我尝试使用带有 geom_sf 和 ggplotly 的 ggplot 为地图制作动画。在以下示例中,地图不会随时间而改变。例如,动画散点图是可能的。任何帮助表示赞赏。

library(sf)
library(tidyverse)
library(plotly)
library("rnaturalearth")
library("rnaturalearthdata")

world <- ne_countries(scale = "medium", returnclass = "sf")
world$year <- 2010

world2 <- world
world2$year <- 2011
world2$pop_est <- 1000000

world3 <- bind_rows(world, world2)
   
plt <- ggplot(world3, aes(fill = pop_est, frame = year)) +
  geom_sf()

ggplotly(plt)

【问题讨论】:

    标签: r ggplot2 plotly


    【解决方案1】:

    我想这就是你要找的:

    library(gganimate)
    world3 %>% ggplot() +
      geom_sf() + aes(fill = pop_est) +
      transition_states(year)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-06
      • 1970-01-01
      • 2021-03-13
      • 2019-02-06
      • 2020-07-15
      • 1970-01-01
      • 1970-01-01
      • 2022-08-03
      相关资源
      最近更新 更多