r - empty page when plotting a network graph using d3Network package -


i'm trying plot network graph using d3network package. tried organizing data match instructions appear on package website (and page), still blank web page. can spot i'm doing wrong?

library(d3network)  g.top3000 <- structure(list(from = structure(c(1l, 1l, 1l, 1l, 1l, 2l, 2l,  2l, 2l, 3l, 3l, 3l, 4l, 4l, 5l), .label = c("afghanistan", "attack",  "people", "pres_bush", "taliban"), class = "factor"), = structure(c(4l,  1l, 5l, 2l, 3l, 1l, 5l, 2l, 3l, 5l, 2l, 3l, 2l, 3l, 3l), .label = c("people",  "taliban", "united_states", "attack", "pres_bush"), class = "factor"),      weight = c(4, 3, 2, 6, 5, 5, 2, 3, 6, 1, 1, 5, 2, 4, 4)), .names = c("from",  "to", "weight"), row.names = c(na, -15l), class = "data.frame")  top3000.nodes <- structure(list(name = structure(1:5, .label = c("afghanistan",  "attack", "people", "pres_bush", "taliban"), class = "factor"),      id = c(1, 1, 1, 2, 2)), .names = c("name", "id"), row.names = c(na,  -5l), class = "data.frame")  d3forcenetwork(links = g.top3000, nodes = top3000.nodes, source = "from", target = "to", value = "weight", nodeid = "name", group = "id", width = 800, height = 400, opacity = 0.9,    file = "projekt2_terror_news_force.html") 

plotting simple graph works fine

d3simplenetwork(g.top3000, width = 800, height = 400, fontsize = 12, linkdistance = 200,    file = "projekt2_terror_news.html") 

that's because

  1. no entry of "united status" in node list.
  2. you may need use numeric index instead of node name.

# add entry "united status" top3000.nodes <- rbind(top3000.nodes, data.frame(name = "united_states", id = 3))  # name index g.top3000$from2 <- sapply(as.character(g.top3000$from), function(x) which(x == top3000.nodes$name))-1 g.top3000$to2 <- sapply(as.character(g.top3000$to), function(x) {     <- which(x == top3000.nodes$name)     if (length(i)) else na     }) -1  # use indices in "from2" , "to2" d3forcenetwork(links = g.top3000, nodes = top3000.nodes, source = "from2", target = "to2", value = "weight", nodeid = "name", group = "id", width = 800, height = 400, opacity = 0.4,    file = "projekt2_terror_news_force.html", linkdistance = 200) 

enter image description here


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -