Pre-Requisite

Disable message and warning. Set plots width to 9.

## Global options
knitr::opts_chunk$set(
               message=FALSE,
               warning=FALSE,
               fig.width=9)

Install packages

packages = c('igraph', 'tidygraph', 'ggraph', 'visNetwork', 'lubridate', 'tidyverse')

for(p in packages){library
  if(!require(p, character.only = T)){
    install.packages(p)
  }
  library(p, character.only = T)
}

Import network data. Ensure the file path is correct

GAStech_nodes <- read_csv("data/GAStech_email_node.csv")
GAStech_edges <- read_csv("data/GAStech_email_edge-v2.csv")

Task 1: Static Organisation Graph

Data Wringling from Hands-on Exercise 10

GAStech_edges$SentDate  = dmy(GAStech_edges$SentDate)
GAStech_edges$Weekday = wday(GAStech_edges$SentDate, label = TRUE, abbr = FALSE)

GAStech_edges_aggregated <- GAStech_edges %>%
  filter(MainSubject == "Work related") %>%
  group_by(source, target, Weekday) %>%
    summarise(Weight = n()) %>%
  filter(source!=target) %>%
  filter(Weight > 1) %>%
  ungroup()

Create Network Objects from Hands-on Exercise 10

GAStech_graph <- 
  tbl_graph(nodes = GAStech_nodes, edges = GAStech_edges_aggregated, directed = TRUE)

GAStech_graph %>%
  activate(edges) %>%
  arrange(desc(Weight))

1.1 Improve the code chunk used to create the organisation network graph by using the latest functions provided in ggraph2.0.

g <-GAStech_graph %>%
  mutate(betweenness_centrality = centrality_betweenness()) %>%
  mutate(closeness_centrality = centrality_closeness()) %>%
  #Modified code
  qgraph(node_size = betweenness_centrality, node_colour = closeness_centrality)
g

1.2 Identify three aspects of the graph visualisation in Section 6.1 that can be improved.

  • Lack of labelling in general poses a difficulty for users to interpret any meaningful information.
  • Difficult to differentiate edges becuase of the thickness of black edges overlapping with some nodes.
  • The color of the nodes are hard to see due to lower closeness centrality i.e. darker colour

1.3 Provide the sketch of your alternative design.

1.4 Using appropriate ggraph functions, plot the alternative design.

Overall Network Graph

GAStech_graph<- GAStech_graph %>%
  mutate(betweenness_centrality = centrality_betweenness()) %>%
  mutate(closeness_centrality = centrality_closeness()) 

g <- ggraph(GAStech_graph, layout="nicely") +
  geom_edge_link0(aes(edge_width=Weight), color="grey66", alpha=0.3) +
  geom_node_point(aes(colour = closeness_centrality, size=betweenness_centrality)) +
  scale_edge_width_continuous(range = c(0.2,0.9))+
  scale_size_continuous(range=c(2,8)) + 
  scale_color_gradient(low="#ff0000", high="#ffeb3b") +
  theme_graph() + theme(legend.position = "left")

g + geom_node_label(aes(filter=closeness_centrality > 0.015, label= label), repel = TRUE)+
  ggtitle("Centrality indices Chart") 

Network Graph by Department

The overall network graph does provide critical information regarding the key employees and its interaction with other employees. However, it does not display which department Mat, Birgitta, Hideki and Ruscella often interact with and the frequency of interaction as indicated by the weight of the edges. The thicker the edges, the higher the frequency of interaction.

The graph below is categorised/faceted by Department.

g + facet_nodes(~Department) + 
  geom_node_label(aes(filter=closeness_centrality > 0.010, label= label), 
                  repel = TRUE) +
  ggtitle("Centrality indices Chart by Department") 

Task 2: Interactive Organisation Graph

Data Preparation from Hands-on Exercise 10

GAStech_edges_aggregated <- GAStech_edges %>%
  left_join(GAStech_nodes, by = c("sourceLabel" = "label")) %>%
  rename(from = id) %>%
  left_join(GAStech_nodes, by = c("targetLabel" = "label")) %>%
  rename(to = id) %>%
  filter(MainSubject == "Work related") %>%
  group_by(from, to) %>%
    summarise(weight = n()) %>%
  filter(from!=to) %>%
  filter(weight > 1) %>%
  ungroup()
GAStech_edges_aggregated
## # A tibble: 839 x 3
##     from    to weight
##    <dbl> <dbl>  <int>
##  1     1     2     21
##  2     1     3     21
##  3     1     4     21
##  4     1     5     21
##  5     1     6     21
##  6     1     7     21
##  7     1     8     15
##  8     1     9     15
##  9     1    10     15
## 10     1    11     15
## # … with 829 more rows

Based on Hands-on exercise 10, the visNetwork() looks for a field called “group”. Rename Department column to group

GAStech_nodes <- GAStech_nodes %>%
  rename(group = Department)
GAStech_nodes

2.1 Improve the design of the graph by incorporating the following interactivity:

  • When a name is selected from the drop-down list, the corresponding node will not only be highlighted but also will be labelled. Furthermore, all the linked nodes of the selected node will also be labelled too.

  • When a node of the interactive graph is selected, the node will not only be highlighted but also will be labelled. Furthermore, all the linked nodes of the selected node will be labelled as well.

In the code chunk below, VisNodes is used to incorporate the font size and scaling. With regards to scaling, there are 2 proterties:

  • Threshold - When zooming out, the font will be drawn smaller. It defines the minimum limit

  • maxVisible - When zooming in, the font will be drawn larger. It defines the maximum limit

visNetwork(GAStech_nodes, GAStech_edges_aggregated) %>%
  visNodes(font = list(size=30), 
           scaling = list(label=list(Threshold=30, maxVisible=60))) %>%
  visIgraphLayout(layout = "layout_with_fr") %>%
  visOptions(highlightNearest = list(enabled = T, degree = 0), nodesIdSelection = TRUE) 

2.2 Identify three aspects of the graph visualisation in Section 7.4 that can be improved.

  • Due to complicated connections, the label for each node is hard to read
  • Without labelling what each color represents, users cannot identify which department is which
  • Cannot filter by specific department

2.3 Provide the sketch of your alternative design.

2.4 Using appropriate visNetwork functions, plot the alternative design.

visNetwork(GAStech_nodes, GAStech_edges_aggregated) %>%
  visIgraphLayout(layout = "layout_with_fr") %>%
  visOptions(highlightNearest = list(enabled = T, degree = 1, hover = T, 
                                     algorithm ="hierarchical"), 
            selectedBy = list(variable= "group", main="Department"), 
            nodesIdSelection = list(main="Employee Name")) %>%
  visNodes(labelHighlightBold = TRUE, shape = "box", shadow = list(enabled = TRUE, size = 50), 
           font = list(size=30), scaling = list(label=list(Threshold=30, maxVisible=60))) %>%
  visLegend(position="left", zoom=FALSE) %>%
  visEdges(arrows = "to", color = list(highlight="#424242"))