Importing Data/Libraries
packages = c('igraph', 'tidygraph', 'ggraph', 'visNetwork', 'lubridate', 'tidyverse','deldir')
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")
Data Wrangling
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
Task 1: Static Organisation Graph
Initial Organisation Network Graph from Section 6.1
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()
Task 1.1) Improve the code chunk used to create the organisation network graph by using the latest functions provided in ggraph2.0.
In ggraph2.0, ggraph plots gets constructed without grids and axes. Thus, there is no need to use theme_graph(). In ggraph 2.0, the internals have also been rewritten to be based only on tidygraph. This means that all tidygraph algorithms will be available as input to layout specs and aesthetic mappings. Thus, there is no need to use the mutate() function to create new variables from centrality_closeness() and centrality_betweenness(). Another improvement to note is that creation of a tbl_graph is not necessary anymore.
The new code chunk using the latest functions provided in ggraph2.0 is shown below:
ggraph(GAStech_graph,layout = "nicely") +
geom_edge_link(aes()) +
geom_node_point(aes(colour = centrality_closeness(), size=centrality_betweenness()))
Task 1.2) Identify three aspects of the graph visualisation in Section 6.1 that can be improved.
Task 1.3) Provide the sketch of your alternative design.
Task 1.4) Using appropriate ggraph functions, plot the alternative design.
ggraph(GAStech_graph,layout = "nicely") +
geom_node_voronoi(aes(fill = Department), max.radius = 0.3, colour = 'white', alpha = 0.2) +
geom_edge_link(aes(width=Weight), alpha=0.2) +
scale_edge_width(range = c(0.1, 5)) +
geom_node_point(aes(colour = centrality_closeness(), size=centrality_betweenness())) +
scale_color_gradient(low='red', high='green') +
geom_node_text(aes(label = label), colour = "black", repel = TRUE, size = 2) +
theme_graph(background = 'white') +
labs(title="GAStech centrality indices",colour="Closeness Centrality",size="Betweenness Centrality")
Task 2: Interactive Organisation Graph
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)
Initial Organisation Network Graph from Section 7.4
visNetwork(GAStech_nodes, GAStech_edges_aggregated) %>%
visIgraphLayout(layout = "layout_with_fr") %>%
visOptions(highlightNearest = TRUE, nodesIdSelection = TRUE)
Task 2.1) Improved interactivity of the graph.
The interactivity of the graph is improved with the following code:
visNetwork(GAStech_nodes, GAStech_edges_aggregated) %>%
visIgraphLayout(layout = "layout_with_fr") %>%
visOptions(highlightNearest = list(enabled = TRUE,degree = 1, labelOnly = FALSE, hover = FALSE),nodesIdSelection = TRUE)
Task 2.2) Identify three aspects of the graph visualisation in Section 7.4 that can be improved.
Task 2.3) Provide the sketch of your alternative design.
Task 2.4) Using appropriate visNetwork functions, plot the alternative design.
GAStech_edges_aggregated <- rename(GAStech_edges_aggregated, value = weight)
GAStech_nodes <- rename(GAStech_nodes,title = Title)
visNetwork(GAStech_nodes, GAStech_edges_aggregated) %>%
visNodes(font = list(size=40,color = "black"), title = "Title") %>%
visLegend(position = "right", main = "Department") %>%
visIgraphLayout(layout = "layout_with_fr") %>%
visEdges(arrows = "to") %>%
visOptions(highlightNearest = list(enabled = TRUE,degree = 1, labelOnly = FALSE, hover = FALSE),nodesIdSelection = TRUE,selectedBy = "group") %>%
visInteraction(navigationButtons = T)