Importing Libraries and Reading Files

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)
}
GAStech_nodes <- read_csv("/Users/kelvincsw/Google Drive/SMU Stuffs/Sem 3.1/VA/Week 11/data/GAStech_email_node.csv")
GAStech_edges <- read_csv("/Users/kelvincsw/Google Drive/SMU Stuffs/Sem 3.1/VA/Week 11/data/GAStech_email_edge-v2.csv")

Manipulating Data

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

Creating the graph

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

Original Output

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

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

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

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

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

1. Links Color The links in the original graph is black and it creates too much distraction in the graph. It is also harder for users to determine the lines. Hence, it should be replaced with a lighter color like light grey.

2. Node Color
The color of the nodes is using a sequential color scheme and it is hard to users to determine the centrality closeness. Hence, a diverging color scheme can be adopted to better distinguish them.

3. Node Label
The node should be labelled to allow the user to visualise which employee have high centrality betweenness and closeness.

Provide the sketch of your alternative design.

Using appropriate ggraph functions, plot the alternative design.

ggraph(GAStech_graph, layout="nicely") + 
  geom_edge_link(colour="#BBBBBB") +
  geom_node_point(aes(size=centrality_betweenness(),colour=centrality_closeness())) +
  geom_node_text(aes(label=label), repel=TRUE, size =2.5,colour="black")+
  scale_colour_gradient(low="#ED4534",high="#74FF9C")

Aggregating and filtering edges

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

Renaming columns to match visNetwork

GAStech_nodes <- GAStech_nodes %>%
  rename(group = Department) %>%
  rename(title = Title)

Original Output

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

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

Improve the design of the graph by incorporating the following interactivity:

  1. 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.
  2. 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.
GAStech_nodes <- GAStech_nodes %>% mutate(font.size = 50)

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

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

1. Missing Legend
Users do not know what the color coding of each node represents. There should be a legend to display the color code for each department.

2. More filter options
Users are unable to select multiple nodes that belong to the same department. To allow for in-depth analysis for interactions between departments, a new filter can be implemented to group nodes by departments.

3. Lack of navigation control
The controls to zoom in/out, reset view is not clearly defined and new users may face difficulty interacting with the interface. Navigation control buttons can be implemented to allow users to easily navigate the graph.

Provide the sketch of your alternative design.

Using appropriate visNetwork functions, plot the alternative design.

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

#Groups had to be manually color coded to reflect to the legend correctly.

visual <- visNetwork(GAStech_nodes, GAStech_edges_aggregated) %>%
  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;')) %>% 
  visLegend(position = "right", main = "Department") %>%
  visGroups(groupname = "Facilities", color = "pink", shadow = list(enabled = TRUE)) %>%
  visGroups(groupname = "Executive", color = "lightgreen", shadow = list(enabled = TRUE)) %>%
  visGroups(groupname = "Administration", color = "lightblue", shadow = list(enabled = TRUE)) %>%
  visGroups(groupname = "Engineering", color = "cyan", shadow = list(enabled = TRUE)) %>%
  visGroups(groupname = "Security", color = "yellow", shadow = list(enabled = TRUE)) %>%
  visGroups(groupname = "Information Technology", color = "#C681FF", shadow = list(enabled = TRUE))

visInteraction(visual,dragNodes = TRUE,navigationButtons = T)