如何使用R中的MDSJ渲染引擎渲染networkDynamic网络?

时间:2016-09-01 15:40:44

标签: r sna statnet

我想使用快速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,可以获得这样的动态视图:

enter image description here

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

enter image description here

1 个答案:

答案 0 :(得分:0)

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