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)
GAStech_graph %>%
activate(edges) %>%
arrange(desc(Weight))
## # A tbl_graph: 54 nodes and 1456 edges
## #
## # A directed multigraph with 1 component
## #
## # Edge Data: 1,456 x 4 (active)
## from to Weekday Weight
## <int> <int> <ord> <int>
## 1 40 41 Tuesday 23
## 2 40 43 Tuesday 19
## 3 41 43 Tuesday 15
## 4 41 40 Tuesday 14
## 5 42 41 Tuesday 13
## 6 42 40 Tuesday 12
## # ... with 1,450 more rows
## #
## # Node Data: 54 x 4
## id label Department Title
## <dbl> <chr> <chr> <chr>
## 1 1 Mat.Bramar Administration Assistant to CEO
## 2 2 Anda.Ribera Administration Assistant to CFO
## 3 3 Rachel.Pantanal Administration Assistant to CIO
## # ... with 51 more rows
With reference to the organisation network graph in Section 6.1 of Hands-on Exercise 10, you are required to complete the following tasks:
Before Improvements:
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()
After Improvements:
Explanation:
In ggraph2.0, ggraph gained a new function “qgraph()”. This function allows an easier and quicker overview over the network data by inspecting the input and automatically picks a layout and combination of edge and node geoms.
In the older version of ggraph, “theme_graph()” had to be used deliberately to avoid overwriting any defaults. In ggraph2.0, it is no longer required to deliberately specify a theme_graph() function as the ggraph plot will still use the default theme as its base. Additionally, theme_graph() still exists and can be used.
g <- GAStech_graph %>%
mutate(betweenness_centrality = centrality_betweenness()) %>%
mutate(closeness_centrality = centrality_closeness())
qgraph(
g,
node_colour = closeness_centrality,
node_size = betweenness_centrality
)
Problem 1: Unable to identify what are the specific titles of each employee of each node.
Solution 1: Include labels to indicate the titles of employees in the network graph.
Problem 2: Unable to identify which department the employees of each node belongs to.
Solution 2: Use outline color differentiation for each node to differentiate the different departments in which the employee belongs to.
Problem 3: The color of the edges are too dark. Resulted in the nodes being covered by the dark edges and obscuring the darker nodes.
Solution 3: Use a lighter color for the edges and use a more contrasting colour for the nodes against the color of the edges.
knitr::include_graphics("data/task1_sketch.jpg")
ggraph(g) +
geom_edge_link(colour = "grey") +
geom_node_circle(aes(fill = closeness_centrality, r = log(betweenness_centrality)/80, col = Department), size = 1) +
geom_node_text(aes(label = Title), colour = "gray48", label.size = 2, check_overlap = TRUE) +
theme_graph(background = NA)
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)
With reference to the organisation network graph in Section 7.4 of Hands-on Exercise 10, you are required to complete the following tasks:
visNetwork(GAStech_nodes, GAStech_edges_aggregated, height = "500px", width = "100%") %>%
visIgraphLayout(layout = "layout_with_fr") %>%
visOptions(highlightNearest = list(enabled = TRUE, degree = list(from = 1, to = 1)),
nodesIdSelection = list(enabled = TRUE,
style = 'width: 200px; height: 26px;
background: #f8f8f8;
color: darkblue;
border:none;
outline:none;'))
Problem 1: Unable to identify the interaction between nodes, whether or not the interaction is uni-directional or bi-directional.
Solution 1: Include arrows in the edges to allow visualisation of interaction of nodes.
Problem 2: Unable to clearly identify edges due to overlapping of the many edges.
Solution 2: Since it is inevitable for edges to overlap one another, allowing to drag nodes to another position enables users for a clearer view of the edges to avoid overlapping.
Problem 3: Labels placed under the node may overlap one another and also, overlap the many edges. This will cause confusion and difficulty in reading.
Solution 3: Place the labels within the nodes itself.
knitr::include_graphics("data/task2_sketch.jpg")
visNetwork(GAStech_nodes, GAStech_edges_aggregated, height = "500px", width = "100%", main = "Interactive Organisation Graph") %>%
visIgraphLayout(layout = "layout_with_fr") %>%
visEdges(smooth = FALSE) %>%
visPhysics(stabilization = FALSE) %>%
visInteraction(dragNodes = TRUE, dragView = TRUE,zoomView = TRUE) %>%
visNodes(shape = "box" ,shadow = list(enabled = TRUE, size = 10)) %>%
visEdges(arrows = "to" ,shadow = FALSE,color = list(highlight = "#C62F4B")) %>%
visOptions(highlightNearest = list(enabled = TRUE, degree = list(from = 1, to = 1)),
nodesIdSelection = list(enabled = TRUE, values = unique(GAStech_nodes$id),
style = 'width: 200px; height: 26px;
background: #f8f8f8;
color: darkblue;
border:none;
outline:none;'))