Importing Data/Libraries

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

for(p in packages){library
  if(!require(p, character.only = T)){
    install.packages(p)
  }
  library(p, character.only = T)
}
GAStech_nodes <- read_csv("data/GAStech_email_node.csv")
GAStech_edges <- read_csv("data/GAStech_email_edge-v2.csv")

Data Wrangling

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

Task 1: Static Organisation Graph

  1. Improve the code chunk used to create the organisation network graph by using the latest functions provided in ggraph2.0.
  2. Identify three aspects of the graph visualisation in Section 6.1 that can be improved.
  3. Provide the sketch of your alternative design.
  4. Using appropriate ggraph functions, plot the alternative design.

Initial Organisation Network Graph from Section 6.1

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()

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

In ggraph2.0, ggraph plots gets constructed without grids and axes. Thus, there is no need to use theme_graph(). In ggraph 2.0, the internals have also been rewritten to be based only on tidygraph. This means that all tidygraph algorithms will be available as input to layout specs and aesthetic mappings. Thus, there is no need to use the mutate() function to create new variables from centrality_closeness() and centrality_betweenness(). Another improvement to note is that creation of a tbl_graph is not necessary anymore.

The new code chunk using the latest functions provided in ggraph2.0 is shown below:

ggraph(GAStech_graph,layout = "nicely") + 
  geom_edge_link(aes()) +
  geom_node_point(aes(colour = centrality_closeness(), size=centrality_betweenness()))


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

  1. Problem: It is not possible to tell the frequency of interactions between two different nodes.
    Solution: Weight of edges should be reflected by modifying the width of the edges. This will allow users to determine which relationships are stronger.
  2. Problem: No information is provided for who each node refers to and which department they are from.
    Solution: Labels and background colours for nodes should be shown to allow user to easily see the name of each node and which department they belong to. This will allow for a more detailed visualisation.
  3. Problem: It is difficult to view the graph as edge lines are too dark and this makes it difficult to differentiate some nodes from the edges.
    Solution: A brighter colour should be used for the nodes. Opacity should also be introduced to tone down the colour of the edges to easily see the network.

Task 1.3) Provide the sketch of your alternative design.

Task 1.4) Using appropriate ggraph functions, plot the alternative design.

ggraph(GAStech_graph,layout = "nicely") + 
  geom_node_voronoi(aes(fill = Department), max.radius = 0.3, colour = 'white', alpha = 0.2) +
  geom_edge_link(aes(width=Weight), alpha=0.2) +
  scale_edge_width(range = c(0.1, 5)) +
  geom_node_point(aes(colour = centrality_closeness(), size=centrality_betweenness())) + 
  scale_color_gradient(low='red', high='green') + 
  geom_node_text(aes(label = label), colour = "black", repel = TRUE, size = 2) +
  theme_graph(background = 'white') +
  labs(title="GAStech centrality indices",colour="Closeness Centrality",size="Betweenness Centrality")

Task 2: Interactive Organisation Graph

  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.
  2. Identify three aspects of the graph visualisation in Section 7.4 that can be improved.
  3. Provide the sketch of your alternative design.
  4. Using appropriate visNetwork functions, plot the alternative design.

Data 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)

Initial Organisation Network Graph from Section 7.4

visNetwork(GAStech_nodes, GAStech_edges_aggregated) %>%
  visIgraphLayout(layout = "layout_with_fr") %>%
  visOptions(highlightNearest = TRUE, nodesIdSelection = TRUE)

Task 2.1) Improved interactivity of the graph.

The interactivity of the graph is improved with the following code:

visNetwork(GAStech_nodes, GAStech_edges_aggregated) %>%
  visIgraphLayout(layout = "layout_with_fr") %>%
  visOptions(highlightNearest = list(enabled = TRUE,degree = 1, labelOnly = FALSE, hover = FALSE),nodesIdSelection = TRUE) 

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

  1. Problem: It is not possible to select by department.
    Solution: The graph visualisation should allow the ability to select by department instead of just id. Legend should also be provided to help users understand which colour of the nodes denotes which department.
  2. Problem: The graph visualisation does not tell the direction (in-degree and out-degree) of the interactions as well as the frequency of the interactions between different employees.
    Solution: Weight and direction of edges should be included to improve this aspect of the graph visualisation to show the relationship between employees.
  3. Problem: It is difficult to determine which node refers to which employee as the labels are too small.
    Solution: The labels for each node should be bigger and title of the node should also be shown when the node is selected.

Task 2.3) Provide the sketch of your alternative design.

Task 2.4) Using appropriate visNetwork functions, plot the alternative design.

GAStech_edges_aggregated <- rename(GAStech_edges_aggregated, value = weight)
GAStech_nodes <- rename(GAStech_nodes,title = Title)

visNetwork(GAStech_nodes, GAStech_edges_aggregated) %>%
  visNodes(font = list(size=40,color = "black"), title = "Title") %>%
  visLegend(position = "right", main = "Department") %>% 
  visIgraphLayout(layout = "layout_with_fr") %>%
  visEdges(arrows = "to") %>%
  visOptions(highlightNearest = list(enabled = TRUE,degree = 1, labelOnly = FALSE, hover = FALSE),nodesIdSelection = TRUE,selectedBy = "group") %>%
  visInteraction(navigationButtons = T)