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("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)
(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()
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()
)
Identify three aspects of the graph visualisation in Section 6.1 that can be improved.
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.
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.
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.
Provide the sketch of your alternative design.
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
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)
(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)
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)
Identify three aspects of the graph visualisation in Section 7.4 that can be improved.
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.
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.
Clarity - User is not able to understand which department is represented by which colour.
Provide the sketch of your alternative
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