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)

Task 1: Static Organization 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.

Organisation network graph in Section 6.1 (Inital)

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()
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font
## family not found in Windows font database

## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

Task 1a) Improved code chunk using using ggraph 2.0

Based on ggraph 2.0, Tidygraph library has been included in ggprah. This means that all functions/algorithms can be used as parameters in the aesthetic and layout function. Hence, creating new variables for centality closeness and centrality betweeness functions as shown in the inital graph is not neccessary anymore. All we need to do is directly include the functions in the asethetic paramters within geom_node_point() function.

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

Task 1b) 3 aspects that can be improved in Graph 6.1

  1. Colour of the nodes
    • The current colour scale used in the graph is in the shade of blues which is not clear in differentiating the centrality closeness.
    • To resolve this, the colour scale has been changed from red to green to make the difference more obvious and intuitive (Red = low, Green = High)
  2. Labels of the nodes
    • The current nodes are not labelled. Readers would not be able to identify which nodes have high or low centrality closeness.
    • To resolve this, the nodes are now labelled with their names hence making identification and referencing possible and much easier.
  3. Clustered network with over lapping links
    • The current graph has a lot of overlapping links which makes it almost impossible to see which nodes are connected to which.
    • To resolve this, the colour of the link is changed to light grey and the thickness of the width has been decreased. This will make the network more clean and less over lapping with the other links and the node lables.
    • In addition, the network has been facted by Departments to breakdown the network. This will allow readers to see the links clearer within departments.

Task 1c) Sketch of proposed design

Task 1d) Proposed alternate Design

To complement the pros & and cons of the proposed alternate design. Two network graphs are being proposed. One showing the whole network and the other being facted. The purpose of this to breakdown the network graph so that the links between nodes can be identified and seen clearer.

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") +
  th_foreground(foreground = "grey80",  border = TRUE)

ggraph(GAStech_graph, layout="kk") + 
  geom_edge_link(colour="darkgrey") +
  geom_node_point(aes(size=centrality_betweenness(),colour=centrality_closeness())) +
  #geom_node_circle(aes(fill = closeness_centralitycol= Department),size=2) +
  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)

Task 2: Interative Organization 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)

1a) Updated Network Graph with Interactivity

The nodes and corresponding nodes now being labelled & highlighted when selected in the drop down box or in the interactive network graph. In addition, the linkes of the selected nodes and its corresponding nodes will be highlighted to.

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)

1b) 3 aspects of the graph visualisation n 7.3 that can be improved

  1. Lack of labelling/legend
    • Currently there is no labelling to tell readers which colours represent the respectively departments.
    • To resolve this, a legend will be placed beside the network graph to inform readers of what the colours of the nodes present.
  2. Providing altenrative to navigation control
    • Currently, there is not much issue with the navigation of the graph by using the mouse.
    • However, to provide an altnerative for navagation, nagivation controls were included.
  3. Unable to see links within Departments
    • Currently, users can only select a node to see its corresponding linked nodes.
    • To provide more detailed breakdown of the network graph, users can now select a department in the dropdown box to see the connections within its own departments.

1c) Sketch of alternative design

1d) Updated Network Graph with Interactivity

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

p <- visNetwork(GAStech_nodes, GAStech_edges_aggregated) %>%
  visLegend(position = "left", main = "Department") %>% 
  visIgraphLayout(layout = "layout_with_fr") %>%
  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,navigationButtons = T)