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

Loading the 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)
}

Prepare the tbl_graph object:

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)

Original code:

g_original <- 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_original + theme_graph()

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

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

Three aspects of the graph visualisation that can be improved:

  1. Labels could be added to the nodes so we know which are the significant nodes.
  2. The color of edges and nodes could be changed for clearer readability purposes.
  3. The current graph has overlapping components and it is hard to visualize the different importance of the nodes. It is better to make the edges and nodes more distinct and introduce one more network metric - Eigenvector Centrality.

Sketch of alternative design (for both task 1 and task 2):

Plot the alternative design:

(I experience 3 iterations and kept improving, until I reach the best design at iteration 3)

Improved iteration 1:

  • Change the edge color to gray. (geom_edge_link(colour=“gray”))
  • Add labels for the nodes, whereas the size of both the label and node indicates betweenness_centrality and the color indicates the closeness_centrality. (geom_node_text,aes(label= , color= , size= ))
  • Add a title for the graph. (ggtitle)
ggraph(GAStech_graph, layout = "nicely") + 
  geom_edge_link(colour="gray") +
  geom_node_point(aes(colour = centrality_closeness(), size=centrality_betweenness()))+
  geom_node_text(aes(label = label, color = centrality_closeness(), size=centrality_betweenness()), repel = TRUE)+
  ggtitle("Network Metrics Analysis - Iteration 1")

Improved iteration 2:

  • Add in eigenvector_centrality as one of the metrics. (centrality_closeness())
  • Only if eigenvector_centrality has a value greater or equal to 0.3, the label of the node is shown. (aes(label = ifelse(centrality_eigen() >= 0.3, label, NA)))
ggraph(GAStech_graph, layout = "nicely") + 
  geom_edge_link(color="gray") +
  geom_node_point(aes(colour = centrality_closeness(), size=centrality_betweenness()))+
  geom_node_text(aes(label = ifelse(centrality_eigen() >= 0.3, label, NA), color = centrality_closeness(), size=centrality_betweenness()), repel = TRUE) +
  ggtitle("Network Metrics Analysis - Iteration 2")

Improved iteration 3 (Final, best design):

  • Change the node from a point to circle, whereas the circle color indicates eigenvector_centrality, the fill of circle indicates closeness_centrality and the size of the circle indicates betweenness_centrality (geom_node_circle(aes(colour= , fill= ,r= , size=))
  • Change the color as red indicates eigenvector_centrality importance, the fill as blue indicates closeness_centrality importance. (scale_color_gradient ,scale_fill_gradient)
  • Add back all labels with black color and a smaller size. (geom_node_text(aes(label=label), colour=“black”,size=3))
  • Add a caption for the graph. (labs(caption=""))
ggraph(GAStech_graph, layout = "nicely") +
  geom_edge_link(colour = "gray") +
  geom_node_circle(aes(colour = centrality_eigen(), fill = centrality_closeness(),r = log(centrality_betweenness())/40), size = 1) +
  scale_color_gradient(low = "pink", high = "red")+
  scale_fill_gradient(low = "white", high = "blue")+
  geom_node_text(aes(label =label), colour = "black",size = 3) + 
  ggtitle("Network Metrics Analysis - Final")+
  labs(caption = "The size of the node indicates the betweenness_centrality")

Task 2: Interactive Organisation Graph

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

Prepare the edges of the tbl_graph object:

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 %>%
  mutate(group = Department)

Original graph:

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

Improve the design of the graph by incorporating the interactivity:

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

Three aspects of the graph visualisation that can be improved:

  1. The labels of the nodes could be shown more obviously, especially when clicked on the nodes, we should know what are those nodes.
  2. The nodes are in different colors but no legend provided the information about colors.
  3. More information about the node can be shown in tooltips when hovering over the node.

Sketch of alternative design:

Please refer to the sketch graph I pasted above, together with task 1 sketch.

Plot the alternative design:

Improved graph:

  • Add in tooltips for the node including name, title and department, shown when hovering over the node. (GAStech_nodes$title <- paste0(“tooltip info”))
  • Add title for the graph. (visNetwork(main=""))
  • Add visOptions to highlight and show labels only for the selected node and linked node. It works when hovering over the node too. (visOptions(highlightNeares =list(enabled=T, labelOnly=F, degree=1, hover=T))
  • Add an option for user to select by Department. (visOptions(selectedBy=“Department”))
  • Add legend for the department colors. (visLegend(zoom=FALSE))
  • Change the node shape to ellipse so it can show the label for nodes clearly. (visNodes(shape=“ellipse”))
  • Bold the label of highlighed node. (visNodes(labelHighlightBold=TRUE))
  • Add navigation buttons for easy manipulation. (visInteraction(navigationButtons = TRUE))
GAStech_nodes$title <- paste0("<p>Name:<br>",GAStech_nodes$label,"<p>Title:<br>",GAStech_nodes$Title,"<p>Department:<br>",GAStech_nodes$Department)

visNetwork(GAStech_nodes, GAStech_edges_aggregated, main="Interactive Organisation Graph") %>%
  visIgraphLayout(layout = "layout_with_fr") %>%
  visOptions(highlightNearest = list(enabled = TRUE,labelOnly= FALSE, degree = 1, hover = TRUE), nodesIdSelection = TRUE, selectedBy = "Department") %>%
  visLegend(zoom=FALSE) %>%
  visInteraction(navigationButtons = TRUE, tooltipDelay = 120) %>%
  visNodes(shape="ellipse",labelHighlightBold = TRUE, font = list(size=40))

References: