1.0 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)
}


2.0 Data Wrangling

2.1 Importing network data from files

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

2.2 Wrangling of the data

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

2.3 Wrangling attributes

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

2.4 Creating network objects using tidygraph

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


3.0 Task 1: Static Organisation Graph

3.1 Existing Organisation Graph

(from Section 6.1 of hands-on exercise 10)

g <- ggraph(GAStech_graph,
            layout = 'nicely') + 
  geom_edge_link(aes()) + 
  geom_node_point(aes(colour = centrality_closeness(),
                      size= centrality_betweenness()))
g + theme_graph()

3.2 Graph Improvement

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

newgraph <- GAStech_graph

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

3.3 Areas of Improvement

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

  1. Bad aesthetic as the edges are too dark which is visually unappealing and reduces the visibility of some of the nodes. To improve, can reduce the edges’ colour to a lighter colour, such as light grey. The colour of the nodes (centrality closeness), can also be changed to more prominent colour scale to increase visibility.

  2. The visualisation lacks clarity as the nodes are not labelled, so there is no information on which employee belongs to which department, and which employee has interactions with which other employee.

  3. The graph has too many edges, making the interactions within each department hard to spot, reducing the aesthetics of the visualisation. Facetting can be used to reduce edge over-plotting, spreading nodes and edges out based on their various departments.

3.4 Alternative Design Sketch

Provide the sketch of your alternative design. Task 1 Sketch

3.5 Alternative Design Plot

ggraph(GAStech_graph, layout="kk") + 
  geom_edge_link(colour="darkgrey") +
  geom_node_point(aes(size=centrality_betweenness(),colour=centrality_closeness())) +
  scale_colour_gradient(low="red",high="green") +
  geom_node_text(aes(label=label), repel=TRUE, size =2.5,colour="black") +
  facet_nodes(~Department,scale="free") +
  th_foreground(foreground = "grey80",  border = TRUE)

# CHANGES MADE:
# 1. Changed the colour of the edges and colour scale for the closeness of centralities
# 2. Added labels for every node.
# 3. Facetted the graphs based on department


4.0 Task 2: Interactive Organisation Graph

4.1 Building Interactive Network Graph with visNetwork

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

4.1.2 Original Interactive Graph Plot

(from Section 7.4 of hands-on exercise 10)

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

4.2 Graph Improvement

Improve the design the graph by incorporating the following interactivity:
- When a name is selected from the drop-down list, the correspinding node will not only be highlighted but also will be labelled. Furthermore, all the linked nodes of the selected node will be labelled too.
- When a node of the interactive graph is selected, the node will not only be highlighted but also will be labelled. Futhermore, all the linked nodes of the selected node will be labelled as well.

GAStech_nodes <- GAStech_nodes %>%
  mutate(font.size = 48)

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

4.3 Areas of Improvement

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

  1. Clarity & Aesthetic - Employees within the same department are clustered together, causing the labels to overlap. When a selection is made, highlight nodes’ labels are unreadable as they are clustered together. A solution to this would be to change the type of layout, such that the nodes are grouped differently, instead of being aggregated by department.

  2. Clarity - Each department has been assigned a colour but there is no legend provided to explain to the user which colour represents which department. By allowing the user to select a department of interest using a dropdown, the visualisation can quickly and effectively allow the user to see which nodes belong to that department of interest.

  3. Clarity - User is not able to understand which department is represented by which colour.

4.4 Alternative Design Sketch

Provide the sketch of your alternative Task 2 Sketch

4.5 Alternative Design Plot

GAStech_nodes <- GAStech_nodes %>%
  mutate(font.size = 48)

p <- visNetwork(GAStech_nodes, GAStech_edges_aggregated) %>%
  visLegend(position = "left", main = "Department") %>% 
  visIgraphLayout(layout = "layout_on_sphere") %>%
  visOptions(selectedBy = list(variable = "group",
                               style = 'width: 160px; height: 26px;'),
             highlightNearest = list(enabled= TRUE, 
                                     labelOnly = FALSE),
             nodesIdSelection = list(enabled = TRUE,
                                     style = 'width: 175px; height: 26px;')) 

visInteraction(p,dragNodes = TRUE)
# CHANGES MADE:
# 1. Adopted a new layout to spread out the nodes so that the labels can have minimised overlapping. "layout_on_sphere" has the least amount of labels overlapping when a selection of node by ID or by group - it is the layout with the highest label readability.In instances that there is still overlapping of nodes (core people are linked to EVERYONE), the user can now manually drag the nodes to a more empty area to read the label
# 2. Added selection by group dropdown.
# 3. Added legend for better identification for department