2

我想使用快速 MDSJ 库在 R 中呈现动态网络。然而不幸的是,所有顶点的坐标似乎都在0,0使用这个渲染引擎,而在使用其他布局之一时并非如此 (kamadakawaiGraphviz。如果您粘贴下面的代码,您应该能够重现该问题。

if (!require("pacman")) install.packages("pacman")
library("pacman")
pacman::p_load(network, networkDynamic, ndtv)

#animation.mode = "MDSJ"
#animation.mode = "Graphviz"
animation.mode = "kamadakawai"
people <- c("A","B","C","D","E")
documents <- paste0("a",1:10)
edges <- data.frame(from   = c("A","A","A","B","B","C","D"),
                    to     = c("a1","a2","a3","a4","a5","a1","a1"),
                    active = c(1,2,3,3,4,4,4))
net <- network.initialize(0, directed = TRUE, bipartite = length(people))

add.vertices.networkDynamic(net, 5, vertex.pid = people)
add.vertices.networkDynamic(net, 10, vertex.pid = documents)

net %v% "vertex.names" <- c(people, documents)
net %v% "vertex.col"   <- c(rep("blue", length(people)), rep("gray", length(documents)))
set.network.attribute(net,'vertex.pid','vertex.names')

add.edges.networkDynamic(net,
                         tail = get.vertex.id(net, edges[[1]]),
                         head = get.vertex.id(net, edges[[2]]),
                         edge.pid = paste0(edges[[1]], "->", edges[[2]]))
activate.edges(net, e =  1:7, at = edges[[3]])
reconcile.vertex.activity(net = net, mode = "encompass.edges", edge.active.default = FALSE)

slice.par <- list(start = 1, end = 4, interval = 1, aggregate.dur = 2, rule = "earliest")
compute.animation(net,
                  animation.mode = animation.mode,
                  slice.par = slice.par)
render.d3movie(net,
               slice.par = slice.par,
               displaylabels = TRUE,
               output.mode = "htmlWidget",
               vertex.col = 'vertex.col')

使用 kamadakawai,可以获得如下动态视图:

在此处输入图像描述

使用 MDSJ,所有幻灯片如下所示:

在此处输入图像描述

4

1 回答 1

0

此代码适用于我的带有 MDSJ 的系统。它是否正确安装在您的设备上?首次使用时,必须下载并安装 Java 应用程序 mdsj.jar。

于 2016-09-02T13:23:17.007 回答