Social Network Analysis in R

Alison Link
19 November 2015


New workplace, large college, no idea of who knows whom.

Solution…some kind of network-y “Rolodex”?

Social network analysis "crash course"

  • Nodes & edges
  • Directed vs. undirected
  • Measures of centrality
    • closeness
    • degree centrality
    • betweenness

Thanks, Coursera!

The packages

library(networkD3) # the library formerly known as "d3Network"

Our raw data

Two columns of people: 1) a team member 2) a “Rolodex” contact

Additional columns with attributes:

  • some relating to edges (strength of relationship)
  • some relating to nodes (department affiliation, notes)

Load the data

Read in the .CSV…

raw_csv_data <- read.csv("TEL Network Map - Spring 2015.csv", header=TRUE)

names(raw_csv_data) <- c('TELmember', 'CLAcontact', 'dept', 'context', 'notes', 'strength')


Approach #1: iGraph


Prep the data

We're in luck! The iGraph package's “graph_from_data_frame” takes as an argument…

“A data frame containing a symbolic edge list in the first two columns. Additional columns are considered as edge attributes. Since version 0.7 this argument is coerced to a data frame with”

So, let's convert to an iGraph-friendly data format…

network_graph_data <- graph_from_data_frame(raw_csv_data, directed=FALSE)

Note: This is the simplest way to coerce our data into an iGraph-friendly format. It will treat all columns as edge attributes–something we may or may not want. For a more complicated version that supports vertex attributes, as well, look at the command.

Inspect the data

Look at the vertices…


Look at the edges…


Plot the data