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
graphData <- GAStech_graph %>%
mutate(betweenness_centrality = centrality_betweenness()) %>%
mutate(closeness_centrality = centrality_closeness())
qgraph(
graphData,
node_colour = closeness_centrality,
node_size = betweenness_centrality
)
Problem: Colours used for the edges makes it difficult to the nodes when the nodes have a darker shade. Solution: Use different colours for the nodes and use a different colour for the edges
Problem: No indication of which node refering to people from which Job Title or Role Solution: USe labels to tell users the role in the network diagram
Problem: No indication of which node refering to people from which Department Solution: Use outlines of nodes to identify which node has higher betweenness centrality and higher closeness centrality
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
graphData <- GAStech_graph %>%
mutate(betweenness_centrality = centrality_betweenness()) %>%
mutate(closeness_centrality = centrality_closeness())
ggraph(graphData) +
geom_edge_link(colour = "white") +
geom_node_circle(aes(fill = closeness_centrality, r = log(betweenness_centrality)/50, col = Department), size = 2) +
geom_node_text(aes(label = Title), colour = "gray48", size = 4) +
ggtitle("Betweenness (Size of circles) and closeness (shade of blue) centrality of each nodes")
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 %>%
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)
visNetwork(GAStech_nodes, GAStech_edges_aggregated, height = "700px", width = "100%") %>%
visIgraphLayout(layout = "layout_with_fr") %>%
visOptions(
highlightNearest = list(
degree = list(from = 1, to = 1),
enabled = TRUE
),
nodesIdSelection = TRUE
)
Problem: Don’t know how strong or how frequently the 2 nodes interact with each other. Solution: Add weightage to each relationship by adding thickness of the edge
Problem: Do not know how 2 nodes interact with each other. Is it a uni-directional oe bidirectional relationship. Solution: Add edges with arrows and labels to show the direction and weightage of the relationship
Problem: Lack of flexibility to see how people within the group interact with each other. Solution: Add highlight by group to show relationship within the group itself
Problem: No labels to show job title of each node to better understand the relationship. Solution: Add job title to each nodes to allow users to better understand the relationship between each node
Problem: Due to having too many nodes and relationships, it is difficult to see patterns between nodes. Solution: Allow users to drag each node to a different position. This helps users to get a clearer view as there are many nodes and can become difficult to see.
Problem: Difficult to zoom in and out. Solution: Added navigation buttons for making it easier to zoom in and out
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 %>%
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_edges_aggregated <- rename(GAStech_edges_aggregated, value = weight)
GAStech_nodes <- GAStech_nodes %>%
rename(group = Department)
GAStech_nodes$title <- paste0("<p>Job Title: ", GAStech_nodes$Title, "</p>")
GAStech_edges_aggregated$label <- GAStech_edges_aggregated$value
visNetwork(GAStech_nodes, GAStech_edges_aggregated, height = "700px", width = "100%") %>%
visIgraphLayout(layout = "layout_with_fr") %>%
visEdges(
arrows = list(
to = list(enabled = TRUE),
from = list(enabled = TRUE)
)
) %>%
visOptions(
manipulation = TRUE,
selectedBy = "group",
highlightNearest = list(
degree = list(from = 1, to = 1),
enabled = TRUE
),
nodesIdSelection = TRUE
) %>%
visInteraction(navigationButtons = TRUE)