ndtv 中的动态顶点属性

Dynamic vertex attribute in ndtv

我一直在尝试在 ndtv 中实现动态顶点属性,我实际上设法创建了不同大小的顶点,但经过仔细检查,它们与我认为指定的值不对应。相反,顶点大小与顶点 ID 成正比,第一个 ID 的大小最大。我试图通过为每个周期创建一个具有不同大小参数值的顶点拼写来控制大小

steps <- 500
num_agents <- 40
vs <- as.data.frame(cbind(rep(1:num_agents, each = steps + 1), rep(1:(steps + 1), times = num_agents), rep(1:(steps + 1), times = num_agents)))
names(vs) <- c("vertex.id", "onset", "terminus")
vs$dimension <- gather(means, key = "key", value = "value", names(means)[1]:names(means)[ncol(means)])[,2]

结果如下,其中 vs 是顶点拼写,es 是边拼写

head(vs)
  vertex.id onset terminus dimension
1         1     1        1  5.000000
2         1     2        2  2.777778
3         1     3        3  2.040816
4         1     4        4  1.492537
5         1     5        5  1.388889
6         1     6        6  1.315789

head(es[,1:4])
  onset terminus head tail
1     2      501   12   24
2     2      501    2   24
3     2      501   38    2
4     2      501   21    2
5     2      501   28    2
6     2      501   11   30

trade.net <- network(links[,3:4], directed = TRUE, matrix.type = "edgelist", loops = FALSE, multiple = FALSE, ignore.eval = FALSE)

net.dyn <- networkDynamic(base.net = trade.net, edge.spells = es[,1:4], vertex.spells = vs[,c(2,3,1,4)], create.TEAs = TRUE, vertex.TEA.names = "dimension")


net.dyn <- compute.animation(net.dyn, animation.mode = "kamadakawai",
                  slice.par=list(start = 1, end = 10, interval=1, 
                         aggregate.dur=1, rule='any'))


render.d3movie(net.dyn, usearrows = TRUE, 
       displaylabels = F, 
       bg="#111111", 
       vertex.border="#dddddd",
        vertex.cex = net.dyn %v% 'dimension.active',
       edge.col = '#55555599',
       render.par=list(tween.frames = 10, show.time = FALSE),
       slice.par=list(start = 1 , end = 10, interval = 1, aggregate.dur = 1, rule='any'))

我只渲染了部分数据(501 个周期中的前 10 个),但不仅属性与我的预期不匹配,而且它们在时间上也是不变的。

我发现了一种解决方法,即可以在渲染命令中使用函数。

render.d3movie(net.dyn, usearrows = TRUE, 
       displaylabels = F, 
       bg="#111111", 
       vertex.border="#dddddd",
        vertex.cex = function(slice){
            degree(slice)/sum(degree(slice)) * 10}, 
       edge.col = '#55555599',
       render.par=list(tween.frames = 10, show.time = FALSE),
       slice.par=list(start = 1 , end = 10, interval = 1, aggregate.dur = 1, rule='latest')
       )

这对于我想要实现的目标来说效果很好,但没有使用 TEA。