Interactive and Dynamic Social Network Visualization in R

Prof James P. Curley
6th April 2016

Section II - Interactive Graphs

threejs


Excellent htmlwidget graphjs from threejs package for 3D visualizations

http://bwlewis.github.io/rthreejs/graphjs.html

author: Bryan Lewis

threejs


  • list with edges and nodes data frames
  • igraph object
  • edge data frame with from, to, size, color vars.
  • supports curvature

code for my examples

threejs interactivity


  • Move the mouse over a node to show its label.
  • Hold the left mouse button down and move the mouse to rotate the graph.
  • Hold the right mouse button down and move the mouse to pan.
  • Use the mouse scroll wheel to zoom in and out.
  • Double-click on the plot to reset the view

threejs


mydf <- random_name_df() #function to generate random name edgelist df
g = graph.data.frame(mydf, directed=F) # raw graph
i <- edge.betweenness.community(g)$membership 


#color names or hex(without opacity) are ok
g <- set_vertex_attr(g, "color", 
                     value=c("#e70351", "#e8fd02", "#eb03fe", "#fb9104", "#fd99ee", "#e8d97d", "#ea958a", "#fd01af")[i])

g  <- set_edge_attr(g,"color", value = "black")
g  <- set_edge_attr(g, "weight", value=3)

graphjs(g, repulsion=0.15,bg="white")

you will need to
browser refresh

threejs


#get graph object
g <- graph.adjacency(mat) #adjacency matrix of Columbia's intro-bio friendship network

#get giant component
cl<-clusters(g)
g <- induced.subgraph(g, which(cl$membership == which.max(cl$csize)))

#set node and edge attributes 
bt <- betweenness(g, normalized=T,directed=F)
V(g)$size <- 2*(bt/max(bt)) #sizing nodes by betweenness
V(g)$postbac <- postbac #a vector of college affiliation (CC, Postbac, NA)
V(g)$color <- c("#66ccff", "#ffc299", "#d6d6c2")[postbac]
E(g)$color <- "#e6e6e6"


graphjs(g, repulsion = 0.3, curvature = 0.4, bg="black", fg="white")

threejs

you may need to browser refresh

threejs


live versions:

Friendship Network of Columbia Intro-Bio Students:
http://curleylab.psych.columbia.edu/friendship.html


Community membership of mice (Mus musculus) living in a semi-natural environment:
http://curleylab.psych.columbia.edu/mousecommunity.html

(this uses a bootstrapping method to assess the validity of the edge-betweenness community membership alogrithm).

Next Section