Import library, data & data pre-processing

In preparation to complete the two tasks, we will first import the library packages and data, and perform necessary data pre-processing tasks.

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

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

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 in 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 1a) Propose optimised code in 6.1

To optimise the code, we will remove the mutate() functions used in Network Graph 6.1. In the latest ggraph 2.0, the tidygraph library has been included in the internals of the lastest version, which means that all the algorithms will be available as inputs to the aesthetic (aes) mappings and the layout specifications. There is no need to create new variables for the centrality_closeness() and centrality_betweenness() functions. Hence we can include both functions directly in the aesthetic mappings inside the geom_node_point() parameters.

Next, the new qgraph() function is a new feature that shows an overview of the network data, although it should not be used for more complicated plots.

The attempt to optimise the code in the above graph is as shown:

qgraph(
  GAStech_graph, 
  node_colour = centrality_closeness(), 
  node_size = centrality_betweenness()
)

Task 1b) Three aspects from Network Graph in 6.1 that can be improved

From the initial network graph in 6.1, we can look into the following ways to improve the design:

  1. Colour of the nodes
  • The existing colour gradient scale (that denotes closeness centrality) of the nodes is not clear. It makes it difficult to the degree of closeness centrality for each node.
  • To resolve this issue, the gradient scale can be changed where the minimum colour range could be of a lighter shade.
  1. Layout of the network graph
  • The existing network graph layout shows the edges overlapping with one another, which makes it difficult to interpret the links between each node.
  • To resolve this issue, another layout that reduces the number of edge crossings could be considered.
  1. Colour of the edges (lines)
  • The colour of the edges are too dark, and it is hence tough to differentiate the links between each node.
  • As there is bound to be overlaps between edges, the colour of the lines could be lighter.

Task 1c) Sketch of alternative design

Restrospective to the aspects that could be improved from Network Graph 6.1, the following sketch shows an alternative design:

Task 1d) Plot of alternative design

Based on the sketch in Task 1c), the following network diagram aims improve the current Graph 6.1:

g2 <- GAStech_graph %>%
  mutate(betweenness_centrality = centrality_betweenness()) %>%
  mutate(closeness_centrality = centrality_closeness()) %>%
  ggraph(layout = "nicely") + 
  geom_edge_bend(edge_colour = "gray69") +
  geom_node_point(aes(colour= closeness_centrality, size=betweenness_centrality)) +
  scale_colour_gradient(low = "#ff0015", high = "#00ff37")

g2 + theme_graph()

Task 2: Interactive Organisation Graph

  1. Improve the design of the graph by incorporating the following interactivity:
  1. Identify three aspects of the graph visualisation in Section 7.4 that can be improved.
  2. Provide the sketch of your alternative design.
  3. Using appropriate visNetwork functions, plot the alternative design.

Initial Organisation Network Graph in Section 7.4

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

Task 2a) Improved design’s interactivity

The improved graph has additional interactive features by including two parameters labelOnly and hover, where both are set to FALSE. The code is as shown:

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 2b) Three aspects from graph 7.4 that can be improved

From the initial organisation graph in 7.4, we can look into the following ways to improve the design:

  1. Lack of legend for the colour of nodes
  • The different colours for different groups of nodes would serve no purpose as no legend is given to show what each colour denotes.
  • To resolve this issue, we can include a legend at the side to denote the colour and the department each node (employee) belongs to.
  1. Lack of navigation controls for better usability
  • As the network graph is fairly large, it is relatively inconvenient to navigate the graph when trying to zoom in on a particular group of nodes.
  • To resolve this issue, it will be useful to include navigation controls for the user to zoom in/out and navigate around the graph. This will help improve the interactivity feature of the graph.
  1. Lack of directions between each nodes
  • The existing design does not show the direction of the links between each node, and hence reduces the amount of insights obtained from the graph.
  • To resolve this issue, we will include the direction of arrows/links between the nodes.

Task 2c) Sketch of alternative design

Restrospective to the aspects that could be improved from Network Graph 6.1, additional features are proposed in the alternative design sketch - (1) The node labels could be labelled in the circle of each node to prevent overlapping from the edges; (2) Option included to view nodes by department (group). The following sketch shows an alternative design:

Task 2d) Plot of alternative design

Based on the sketch in Task 2c), the following organisation graph aims improve the current Graph 7.4:

visNetwork(GAStech_nodes, GAStech_edges_aggregated,main = "GAStech E-mail Correspondence Between Employees") %>%
  visNodes(GAStech_nodes, shape = "circle") %>%
  visLegend(position = "left", main = "Department") %>% 
  visEdges(arrows = "to") %>%
  visIgraphLayout(layout = "layout_with_fr") %>%
  visOptions(highlightNearest = list(enabled = TRUE,degree = 1, labelOnly = FALSE, hover = FALSE),nodesIdSelection = TRUE,selectedBy = "group") %>%
    visInteraction(navigationButtons = T)