2

I would like to render a dynamic network in R using the fast MDSJ library. Unfortunately, however, all the vertices' coordinates seem to be 0,0 using this rendering engine, which is not the case when using one of the other layouts (kamadakawai or Graphviz. If you paste the code below, you should be able to reproduce the problem.

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')

Using kamadakawai, one gets a dynamic view like this:

enter image description here

Using MDSJ, all slides look like this:

enter image description here

Mischa
  • 623
  • 5
  • 17

1 Answers1

0

This code works on my system with MDSJ. Does it install correctly on yours? When it's first used, it has to download and install a Java application mdsj.jar.

joncgoodwin
  • 136
  • 6
  • Yes, upon first use, I was asked for permission to download and install MDSJ. This succeeded, and I now do see that MDSJ gets called during the process. For some reason, however, it does not work as expected as explained above. I have Mac OS X 10.11.6 El Capitan and Java 8 Update 101 build 13 and RStudio Version 0.99.896. Did you activate MDSJ in the snippet above by uncommenting the #animation.mode = "MDSJ" and commenting out "kamadakawai"? – Mischa Sep 02 '16 at 13:28
  • Yes, I did. How would I know, assuming that I had never used the software before, that it asks for a java download if I did not? Also, I'm using an earlier version of the Mac OS that does not have the permissions issues of El Capitan, though if your other R packages are working, that should be fine. Does anything else that uses RJava work normally. I also don't use RStudio, though I can't see how that makes any difference. – joncgoodwin Sep 02 '16 at 13:56
  • The package rJava was not installed, but installing it did not change anything. – Mischa Sep 02 '16 at 15:39
  • And what kind of error messages (if any) do you get? I see: `[1] "MDSJ starting stress: 3.2711604543709853" "MDSJ ending stress: 4.0077515393037346E-4" Calculating layout for network slice from time 2 to 4 [1] "MDSJ starting stress: 11.61592059726994" "MDSJ ending stress: 0.5122455877471873" Calculating layout for network slice from time 3 to 5 [1] "MDSJ starting stress: 12.664186182271857" "MDSJ ending stress: 1.306168183018367" Calculating layout for network slice from time 4 to 6 [1] "MDSJ starting stress: 1.8375857926346992" "MDSJ ending stress: 0.07398826173255649" ` – joncgoodwin Sep 02 '16 at 16:08
  • `Calculating layout for network slice from time 1 to 3 [1] "coordinate array is missing entries for row 0 col 0 ?" "coordinate array is missing entries for row 0 col 1 ?" [3] "coordinate array is missing entries for row 1 col 0 ?" "coordinate array is missing entries for row 1 col 1 ?" [5] "coordinate array is missing entries for row 2 col 0 ?" "coordinate array is missing entries for row 2 col 1 ?" [7] "MDSJ starting stress: 6.0" "MDSJ ending stress: 6.0" ` – Mischa Sep 02 '16 at 19:19