1.0 Task 1 Preparation

1.1 Installing and Launching R 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)
}

1.2 Data Wrangling

GAStech_nodes <- read_csv("data/GAStech_email_node.csv")
GAStech_edges <- read_csv("data/GAStech_email_edge-v2.csv")
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()
GAStech_graph <- tbl_graph(nodes = GAStech_nodes, edges = GAStech_edges_aggregated, directed = TRUE)
GAStech_graph %>%
  activate(edges) %>%
  arrange(desc(Weight))
## # A tbl_graph: 54 nodes and 1456 edges
## #
## # A directed multigraph with 1 component
## #
## # Edge Data: 1,456 x 4 (active)
##    from    to Weekday Weight
##   <int> <int> <ord>    <int>
## 1    40    41 Tuesday     23
## 2    40    43 Tuesday     19
## 3    41    43 Tuesday     15
## 4    41    40 Tuesday     14
## 5    42    41 Tuesday     13
## 6    42    40 Tuesday     12
## # ... with 1,450 more rows
## #
## # Node Data: 54 x 4
##      id label           Department     Title           
##   <dbl> <chr>           <chr>          <chr>           
## 1     1 Mat.Bramar      Administration Assistant to CEO
## 2     2 Anda.Ribera     Administration Assistant to CFO
## 3     3 Rachel.Pantanal Administration Assistant to CIO
## # ... with 51 more rows

2.0 Task 1: Static Organisation Graph

With reference to the organisation network graph in Section 6.1 of Hands-on Exercise 10, you are required to complete the following tasks:

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

Before Improvements:

g <- GAStech_graph %>%
  mutate(betweenness_centrality = centrality_betweenness()) %>%
  mutate(closeness_centrality = centrality_closeness()) %>%
  ggraph(layout = "nicely") + 
  geom_edge_link(aes()) +
  geom_node_point(aes(colour = closeness_centrality, size=betweenness_centrality))

g + theme_graph()

After Improvements:

Explanation:

  1. In ggraph2.0, ggraph gained a new function “qgraph()”. This function allows an easier and quicker overview over the network data by inspecting the input and automatically picks a layout and combination of edge and node geoms.

  2. In the older version of ggraph, “theme_graph()” had to be used deliberately to avoid overwriting any defaults. In ggraph2.0, it is no longer required to deliberately specify a theme_graph() function as the ggraph plot will still use the default theme as its base. Additionally, theme_graph() still exists and can be used.

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

qgraph(
  g, 
  node_colour = closeness_centrality, 
  node_size = betweenness_centrality
)

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

Problem 1: Unable to identify what are the specific titles of each employee of each node.
Solution 1: Include labels to indicate the titles of employees in the network graph.

Problem 2: Unable to identify which department the employees of each node belongs to.
Solution 2: Use outline color differentiation for each node to differentiate the different departments in which the employee belongs to.

Problem 3: The color of the edges are too dark. Resulted in the nodes being covered by the dark edges and obscuring the darker nodes.
Solution 3: Use a lighter color for the edges and use a more contrasting colour for the nodes against the color of the edges.

2.3 Provide the sketch of your alternative design.

knitr::include_graphics("data/task1_sketch.jpg")

2.4 Using appropriate ggraph functions, plot the alternative design.

ggraph(g) +
  geom_edge_link(colour = "grey") +
  geom_node_circle(aes(fill = closeness_centrality, r = log(betweenness_centrality)/80, col = Department), size = 1) +
  geom_node_text(aes(label = Title), colour = "gray48", label.size = 2, check_overlap = TRUE) +
  theme_graph(background = NA)

3.0 Task 2 Preparation

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_nodes <- GAStech_nodes %>%
  rename(group = Department)

3.1 Task 2: Interactive Organisation Graph

With reference to the organisation network graph in Section 7.4 of Hands-on Exercise 10, you are required to complete the following tasks:

3.2 Improve the design of the graph by incorporating the specified interactivities

visNetwork(GAStech_nodes, GAStech_edges_aggregated, height = "500px", width = "100%") %>%
  visIgraphLayout(layout = "layout_with_fr") %>%
  visOptions(highlightNearest = list(enabled = TRUE, degree = list(from = 1, to = 1)), 
              nodesIdSelection = list(enabled = TRUE,
                                 style = 'width: 200px; height: 26px;
                                 background: #f8f8f8;
                                 color: darkblue;
                                 border:none;
                                 outline:none;'))

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

Problem 1: Unable to identify the interaction between nodes, whether or not the interaction is uni-directional or bi-directional.
Solution 1: Include arrows in the edges to allow visualisation of interaction of nodes.

Problem 2: Unable to clearly identify edges due to overlapping of the many edges.
Solution 2: Since it is inevitable for edges to overlap one another, allowing to drag nodes to another position enables users for a clearer view of the edges to avoid overlapping.

Problem 3: Labels placed under the node may overlap one another and also, overlap the many edges. This will cause confusion and difficulty in reading.

Solution 3: Place the labels within the nodes itself.

3.4 Provide the sketch of your alternative design.

knitr::include_graphics("data/task2_sketch.jpg")

3.5 Using appropriate visNetwork functions, plot the alternative design.

visNetwork(GAStech_nodes, GAStech_edges_aggregated, height = "500px", width = "100%", main = "Interactive Organisation Graph") %>%
  visIgraphLayout(layout = "layout_with_fr") %>%
  visEdges(smooth = FALSE) %>%
  visPhysics(stabilization = FALSE) %>%
  visInteraction(dragNodes = TRUE, dragView = TRUE,zoomView = TRUE) %>%
  visNodes(shape = "box" ,shadow = list(enabled = TRUE, size = 10)) %>%
  visEdges(arrows = "to" ,shadow = FALSE,color = list(highlight = "#C62F4B")) %>%
  visOptions(highlightNearest = list(enabled = TRUE, degree = list(from = 1, to = 1)), 
              nodesIdSelection = list(enabled = TRUE, values = unique(GAStech_nodes$id),
                                 style = 'width: 200px; height: 26px;
                                 background: #f8f8f8;
                                 color: darkblue;
                                 border:none;
                                 outline:none;'))