我想使用不同的布局为同一个网络设置动画,并使布局之间平滑过渡。我想在gganimate框架内执行此操作。
library(igraph)
library(ggraph)
library(gganimate)
set.seed(1)
g <- erdos.renyi.game(10, .5, "gnp")
V(g)$name <- letters[1:vcount(g)]
l1 <- create_layout(g, "kk")
l2 <- create_layout(g, "circle")
l3 <- create_layout(g, "nicely")
long <- rbind(l1,l2,l3)
long$frame <- rep(1:3, each =10)
Run Code Online (Sandbox Code Playgroud)
按照这种ggplot方法,我以长格式(long)存储节点位置,frame并向每个布局添加一个变量。我试图使其与下面的代码一起使用,它可以正常工作并且几乎是我想要的。但是,我似乎找不到找到包括这些边缘的方法:
ggplot(long, aes(x, y, label = name, color = as.factor(name), frame = frame)) +
geom_point(size = 3, show.legend = F) +
geom_text(show.legend = F) +
transition_components(frame)
Run Code Online (Sandbox Code Playgroud)
我还尝试添加边缘为,geom_segment但最终在节点保持移动的同时使它们变为静态。这就是为什么我使用该ggraph程序包并失败的原因:
ggraph(g, layout = "manual", node.position = long) + …Run Code Online (Sandbox Code Playgroud)