Interactive and Dynamic Social Network Visualization in R

Prof James P. Curley
6th April 2016

Section II - Interactive Graphs


Excellent htmlwidget graphjs from threejs package for 3D visualizations

author: Bryan Lewis


  • 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


mydf <- random_name_df() #function to generate random name edgelist df
g =, directed=F) # raw graph
i <-$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


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

#get giant component
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")


you may need to browser refresh


live versions:

Friendship Network of Columbia Intro-Bio Students:

Community membership of mice (Mus musculus) living in a semi-natural environment:

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

Next Section