library(igraph)

First, I bring in some data on Grime musicians and their collaborations with each other in 2008. Then I clean the network a little bit by deleting the self-loops.

grime_edge_list <- read.csv(file.choose(), header = TRUE)

grime_08 <- graph_from_data_frame(d= grime_edge_list, directed = TRUE)
plot(grime_08)

grime_08_clean <- delete.edges(grime_08, E(grime_08)[which_loop(grime_08)])

plot(grime_08_clean)

Now, using data internal to your graph object you can visualise central people in the network using the vertex.size() argument.

Degree Centrality

par(mar = c(0,0,0,0))
plot(grime_08_clean, vertex.size = degree(grime_08_clean)*2, edge.arrow.size = 0.5)

Betweenness Centrality

par(mar = c(0,0,0,0))
plot(grime_08_clean, vertex.size = betweenness(grime_08_clean)*2, edge.arrow.size = 0.5)

Alternatively, you can use the labels to demonstrate centrality

Degree

par(mar = c(0,0,0,0))
plot(grime_08_clean, vertex.label = degree(grime_08_clean))

Betweenness

par(mar = c(0,0,0,0))
plot(grime_08_clean, vertex.label = betweenness(grime_08_clean))

What about visualising the nature of the relationships? The edges?

par(mar = c(0,0,0,0))
plot(grime_08_clean, edge.width = E(grime_08_clean)$collab_weight, edge.arrow.size = 0.5, vertex.size = 6, vertex.label = NA)

par(mar = c(0,0,0,0))
plot(grime_08_clean, edge.width = E(grime_08_clean)$collab_weight, edge.label = E(grime_08_clean)$collab_weight, edge.arrow.size = 0.5, vertex.size = 6, vertex.label = NA) 

Next, you can attach data external to the network (i.e. node characteristics) and visualise those. I bring in a separate .csv file that has various variables that pertain to the nodes. These are fake characteristics that I made up.

grime_nodes <- read.csv(file.choose()) 
head(grime_nodes)
##            node fake_sales sex
## 1       Asher D         10   m
## 2 Dizzee Rascal         20   m
## 3 Lethal Bizzle         50   m
## 4         Wiley         70   m
## 5   Treble Clef        100   m
## 6       Shystie         95   f

Take a look at this to see what we have available. 2 variables - fake sales (continuous) and the artist’s sex (categorical - dichotomous)

Now we can create a network object that has both the network data and the node characteristics. This section uses the vertices = argument which tells R that there are edges and node characteristics as part of the network. I also clean the selfloops from this edgelist.

grime_full <- graph_from_data_frame(grime_edge_list, vertices = grime_nodes, directed = TRUE)
grime_full_clean <- delete.edges(grime_full, E(grime_full)[which_loop(grime_full)])

We can use these node attributes to visualise more about the network

sex <-ifelse(V(grime_full_clean)$sex == "f", "red", "white")

par(mar = c(0,0,0,0))
plot(grime_full_clean, vertex.color = sex)

We can also set the vertex characteristics to reflect the continuous variable. In this case, the artists’ fake sales.

par(mar = c(0,0,0,0))
plot(grime_full_clean, vertex.size = V(grime_full_clean)$fake_sales/100)