block by timelyportfolio f32dc554021ac5e000609343b4b06eff

d3r d3_table with igraph

Full Screen

assembled with blockbuilder.org


In honor of d3r 0.6.6 hitting CRAN, I wanted to do a quick example of R table to d3 node/link to igraph. Thanks svglite for the easy svg + html.

Code

library(networkD3)
library(d3r)
library(igraph)
library(pipeR)

d3_table(Titanic, c("Class","Survived")) %>>%
  { 
    ig =(as.matrix(.$links[,1:2]) + 1) %>>% graph.edgelist(directed=F)
    E(ig)$weight <- .$links[,3]
    V(ig)$name <- .$nodes[,1] %>>% t %>>% as.character
    V(ig)$weight <- .$nodes$value
    ig
  } %>>%
  (plot.igraph(
    .
    , layout=layout_as_tree
    , vertex.size = V(.)$weight/2000 * 30
    , edge.color="gray"
    , edge.width=E(.)$weight/2000 * 30
    , vertex.label = V(.)$name
  ))   

index.html