gganimate 显示沿某些对象的过渡

gganimate showing transition along some objects

我正在尝试创建动画来显示沿某些节点的过渡。我想显示从 SRC 到 TGT 的点随着强度的过渡变化我的 df 如下所示。

> df
  node intensity Lon Lat
1  SRC      0.90  40  60
2  TGT      0.89  80  40
3  TGT      0.80  40  30
4  TGT      0.99  30  20

library(ggplot2)
 library(gganimate)
 df <- read.table(text = "node intensity Lon Lat
                          SRC .9  40  60 
                            TGT .89 80   40
                            TGT  .8 40 30
                            TGT .99 30     20", header = TRUE)
 ggm <- ggplot(data = df, aes(x = Lon, y = Lat, size= intensity, colour=node)) +
      geom_point(alpha=.5)+
      transition_states(node)+
      labs(title = "test")+ 
      shadow_wake(wake_length = 0.5)

我想要的输出是显示像这样的移动动画

我正在沿帧获取点固定 SRC 和 TGT

您可以通过制作三个源副本并为应该从其源位置到目标位置的每个点分配一个组来获得所需的效果。

https://cran.r-project.org/web/packages/gganimate/vignettes/gganimate.html

The key is the group aesthetic. You may be familiar with this aesthetic from plotting lines and polygons, but in gganimate it takes a more central place. Data that have the same group aesthetic are interpreted as being linked across states. The semantics of the group aesthetic in ggplot2 is such that if it is undefined it will get calculated based on the interaction of all discrete aesthetics (sans label). If none exists, such as in our iris animation, all data will get the same group, and will thus be matched by gganimate.

library(ggplot2)
library(gganimate)
df <- read.table(text = "node intensity Lon Lat grp
                          SRC .9  40  60 1
                          SRC .9  40  60 2
                          SRC .9  40  60 3
                            TGT .89 80   40 1
                            TGT  .8 40 30 2
                            TGT .99 30     20 3", header = TRUE)
ggm <- ggplot(data = df, aes(x = Lon, y = Lat, size= intensity, colour=node, group = grp)) +
  geom_point(alpha=.5)+
  transition_states(node)+
  labs(title = "test")+ 
  shadow_wake(wake_length = 0.5)