Setup

library(igraph)
## 
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
## 
##     decompose, spectrum
## The following object is masked from 'package:base':
## 
##     union

Plotting the Networks

par(mfrow = c(1, 2))

# Bucky Facebook Network data frame
Wis_FB <- read.table("Wisconsin87.txt", header = F)
buckynetwork <- graph_from_data_frame(d = Wis_FB, directed = F)

# Bucky Facebook Network plot
set.seed(2022)
V(buckynetwork)$color <- "red"
plot(buckynetwork, vertex.label = NA, edge.color = NA, vertex.size = 2,
     layout = layout_with_drl, main = "Bucky Facebook Network", sub = "Note: edges have been suppressed")

# Teacher Advice Network adjacency matrix
teachers_links <- read.csv("School28_MooDal_AskAdvice-1.csv", header = T, row.names = 1)
teacher_nodes <- read.csv("School28_MooDal_attr-1.csv", header = T, as.is = T)
teachers_links <- as.matrix(teachers_links)
teachers <- graph_from_adjacency_matrix(teachers_links)

# Teaher Advice Network plot
set.seed(2022)
V(teachers)$color <- ifelse(teacher_nodes[V(teachers), 3] == "1", "gray50",
                            ifelse(teacher_nodes[V(teachers), 3] == "2", "tomato", "gold"))
plot(teachers, vertex.label = NA, edge.arrow.size = 0.2, vertex.size = teacher_nodes$YrsCurSite,
     main = "Teacher Advice Network", sub = "Nodes weighted by no. of years at current site")
colors <- c("gray50", "tomato", "gold")
legend(x = -1.5, y = -1.1, c("Fourth Grade", "Fifth Grade", "Principal"), pch = 21,
       col = "#777777", pt.bg = colors, pt.cex = 1.5, cex = .8, bty = "n", ncol = 1)