是否可以使用gganimate创建平滑过渡的动画geom_polygon图?

时间:2020-06-07 14:59:07

标签: r ggplot2 maps

在处理敏感数据时,我深表歉意,因此无法提供完全再现所见错误的步骤,但是在谷歌搜索时,我似乎找不到在R中生成动画图/ geom_polygon图的成功示例。想要创建一个GIF,使地图保持不变,但颜色会随着时间变化:

df_beds_with_map %>% 
    ggplot(aes(x = long, y = lat, group = group, fill = 100 * CriticalCareRatio)) + 
        geom_polygon(colour = "white") +
        # Remove grid lines
        theme_void() +
        # Ensure correct aspect ratio
        coord_map() +
        # Facet by day
        # facet_grid(. ~ Date, switch = "x") +
        scale_fill_gradientn(limits = c(0, 100), colors=c("#34a853", "#fbbc05", "#ea4335")) +
        labs(title = "Critical Care Capacity at {frame_time}", fill = "Capacity (%)") +
        transition_time(Date) +
        ease_aes('linear')

这会导致以下错误,因为我无法分辨from是什么,所以我正在努力调试它:

Error in from[[1]] : subscript out of bounds

任何指出如何找出问题所在的指针都将受到赞赏。

遵循at80的建议的新代码,这似乎只是绘制黑点而不是线条,并且没有可见的填充:

df_beds_with_map %>%
    filter(!is.na(lat) & !is.na(long)) %>%
    st_as_sf(coords=c('long', 'lat'), crs=4326) %>%
    ggplot() + 
        geom_sf(aes(fill = 100 * CriticalCareRatio)) +
        # Remove grid lines
        theme_void() +
        # Ensure correct aspect ratio
        # coord_sf(datum=st_crs(4326)) +
        # Facet by day
        # facet_grid(. ~ Date, switch = "x") +
        # Define colour palette
        scale_fill_gradientn(limits = c(0, 100), colors=c("#34a853", "#fbbc05", "#ea4335")) +
        labs(title = "Critical Care Capacity at {frame_time}", fill = "Capacity (%)") +
        transition_time(Date) +
        ease_aes('linear')

0 个答案:

没有答案
相关问题