【问题标题】:Wiggling lines when animating ggplot choropleth with gganimate使用 gganimate 为 ggplot choropleth 设置动画时摆动线条
【发布时间】:2020-04-01 17:58:20
【问题描述】:

我在使用gganimate 对使用ggplot2 制作的等值线图进行动画处理时遇到问题。

我的一些数据可用here,代码是:

library(tidyverse)
library(gganimate)

part_data <- readRDS(file = "part_data.Rds")

p <- part_data %>%
  ggplot(aes(x = long, y = lat, group = group)) +
  geom_polygon(aes(fill = confirmed), color = "grey70", size = 0.05) +
  coord_map() +
  scale_fill_distiller(trans = "log10", direction = 1, palette = "YlOrRd", na.value = "white") + 
  transition_time(time = date)

animate(p,
        fps = 3, 
        duration = 5,
        renderer = gifski_renderer("countyevolution.gif"),
        width = 1200, height = 750, res = 100)

产生这个 GIF:

也许很难看到,但如果您仔细观察,您会发现县之间的边界在摆动。当我使用transition_manual 没有日期之间的转换时,不会发生这种情况,因此它必须来自这些转换。但为什么呢?

是否有可能以某种方式告诉gganimate 保持边框相同并且只为每一帧渲染fill?或者我可以以其他方式使边界不那么明显吗?我尝试减少size,但这似乎并没有什么不同。另外,边框看起来有点锯齿状。

【问题讨论】:

    标签: r ggplot2 choropleth gganimate


    【解决方案1】:

    这也发生在最近他们身上:包含地图或其他静态元素的动画情节变得摆动或闪烁。我意识到摆动的发生是因为gganimate 也在动画的每个步骤中为地图线设置动画。这就解释了为什么使用其他过渡模式或移除过渡动画可以解决闪烁问题。

    this question 中所述,要排除 ggplot 图层的动画效果,您需要添加 data 参数。这样,背景中的地图或情节将保持静态,而情节的其余部分将进行动画处理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-17
      • 2020-02-02
      • 2021-02-22
      • 2021-02-23
      相关资源
      最近更新 更多