For the final project, you might want to use some data from an actual company to showcase the sort of analysis that you could do for the organization that you choose to focus on.

There is a great set of network data at https://github.com/schochastics/networkdata. You can install all of them with the following (you will only need to run this once - uncomment these lines, run them, and after that comment them out with # like I do below).

#install.packages('drat')
#drat::addRepo("schochastics")
#install.packages("networkdata")

After it’s installed, we load it and set options

knitr::opts_chunk$set(echo = TRUE)
library(networkdata)
library(igraph)
library(tidyverse)
library(ggraph)
library(tidygraph)

The data we want is stored in three igraph networks that came from observing and surveying managers in a high-tec company. They are called ht_advice, ht_friends, and ht_reports.

There are a few other data sources that might be interesting to you - you can look at all of them by running data(package = "networkdata")

I am giving some basic examples of some simple things you could do. I expect you to be creative and insightful, and to build on what I am doing.

Not all of your “visualizations” need to be network graphs. For example, this is one way to prepare a report about who is influential.

ht_advice <- ht_advice %>% as_tbl_graph() %>%
  activate(nodes) %>%
  mutate(betweenness = centrality_betweenness(),
         degree = centrality_degree(mode='in'),
         closeness = centrality_closeness(mode='in', normalized=T)
         )

ht_advice %>%
  select(betweenness, degree, closeness) %>%
  data.frame() %>%
  arrange(desc(betweenness))

You already know how to change the size/color of nodes based on one of these measures.

ht_advice %>%
  ggraph() + 
  geom_edge_fan(color='gray') +
  geom_node_point(aes(color=betweenness), size = 3) +
  scale_color_viridis_c() +
  theme_graph()
## Using `stress` as default layout

Or you might look at whether younger members are being integrated… (remember, you can view attributes using this code):

ht_advice
## # A tbl_graph: 21 nodes and 190 edges
## #
## # A directed simple graph with 1 component
## #
## # Node Data: 21 x 7 (active)
##     age tenure level  dept betweenness degree closeness
##   <dbl>  <dbl> <dbl> <dbl>       <dbl>  <dbl>     <dbl>
## 1    33      9     3     4       13.7      13     0.667
## 2    42     20     2     4        5.94     18     0.909
## 3    40     13     3     2        6.60      5     0.556
## 4    33      8     3     4       13.7       8     0.625
## 5    32      3     3     2        5.08      5     0.5  
## 6    59     28     3     1        0        10     0.667
## # … with 15 more rows
## #
## # Edge Data: 190 x 2
##    from    to
##   <int> <int>
## 1     1     2
## 2     1     4
## 3     1     8
## # … with 187 more rows

For example, this shows those under the median age as a different color, and uses the friendship network.

ht_friends %>% 
  as_tbl_graph() %>% # Convert to a graph that ggraph can use
  mutate(young = age < median(age)) %>% # Create a new variable for whether someone is "young"
  ggraph() + 
  geom_edge_fan(color='gray') +
  geom_node_point(aes(color=young), size=3)+
  theme_graph() + 
  scale_color_viridis_d() # Change the color scale to make it prettier
## Using `stress` as default layout

Finally, we might look for cross-departmental ties. Here’s one way to do that, using custom colors:

# Set a color for each department (0-4)
dept_colors = c('orange','green','tomato','royalblue', 'purple')

ht_advice %>%
  as_tbl_graph() %>%
  mutate(dept = as.factor(dept)) %>%
  ggraph() +
  geom_edge_fan(color='gray') +
  geom_node_point(aes(color=dept), size=3)+
  theme_graph() + 
  scale_color_manual(values = dept_colors) # Set the manual colors
## Using `stress` as default layout