packages = c('igraph', 'tidygraph', 'ggraph', 'visNetwork', 'lubridate', 'tidyverse', 'knitr')
for(p in packages){library
if(!require(p, character.only = T)){
install.packages(p)
}
library(p, character.only = T)
}
GAStech_nodes <- read_csv("C:/Users/alexi/Documents/data/GAStech_email_node.csv")
GAStech_edges <- read_csv("C:/Users/alexi/Documents/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_edges_aggregated
## # A tibble: 1,456 x 4
## source target Weekday Weight
## <dbl> <dbl> <ord> <int>
## 1 1 2 Monday 4
## 2 1 2 Tuesday 3
## 3 1 2 Wednesday 5
## 4 1 2 Friday 8
## 5 1 3 Monday 4
## 6 1 3 Tuesday 3
## 7 1 3 Wednesday 5
## 8 1 3 Friday 8
## 9 1 4 Monday 4
## 10 1 4 Tuesday 3
## # ... with 1,446 more rows
GAStech_graph <- tbl_graph(nodes = GAStech_nodes, edges = GAStech_edges_aggregated, directed = TRUE)
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()
1. Formatting: node color & centrality color centrality color is difficult to ascertain due to full-black color and node color is indistinguishable due to gradient of the same color
2. Node label is missing, thus unable to identify which node belongs to which employee
3. Adding new information: department to provide a clearer overview of the departments of employees that they are networked to
"insert graph here"
## [1] "insert graph here"
ggraph(GAStech_graph, layout="nicely") +
geom_node_voronoi(aes(fill = Department), max.radius = 0.2, colour = 'white',alpha=0.5) +
geom_edge_link(colour="grey") +
geom_node_text(aes(label=label), repel=TRUE, size =2.5,colour="black")+
scale_colour_gradientn(colours = rainbow(4))+
geom_node_point(aes(size=centrality_betweenness(),colour=centrality_closeness()))+
labs(title = "GAStech email network", colour="Closeness centrality", size="Betweenness centrality") +
theme(legend.position = "right",
legend.text = element_text(size = 8),
legend.title = element_text(size = 11),
legend.key.width = unit(2,"cm"),
legend.key.height = unit(0.2,"cm"))
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) %>%
visIgraphLayout(layout = "layout_with_fr") %>%
visOptions(highlightNearest = TRUE, nodesIdSelection = TRUE)
visNetwork(GAStech_nodes, GAStech_edges_aggregated, width = "100%") %>%
visIgraphLayout(layout = "layout_with_fr") %>%
visOptions(nodesIdSelection = TRUE, highlightNearest = list(enabled= TRUE, labelOnly = FALSE)) %>%
visNodes(font = list(size=40))
1. Lack of legends and title: each node color is not known to users, which makes it difficult to comprehend which department they are from
2. User experience: view is easily altered by zoom-in/zoom-out functions, reset to default view is not available
3. Adding analytical tool: add filter option and tool tip this allows user to conduct second-level analysis by filtering department while the tool tip improves the overall information presented
"insert sketch here"
## [1] "insert sketch here"
GAStech_nodes$title <- paste0("<p>Name:<br>",GAStech_nodes$label,"<p>Title:<br>",GAStech_nodes$Title,"<p>Group:<br>",GAStech_nodes$group)
visNetwork(GAStech_nodes, GAStech_edges_aggregated, main="GASTech email network", width = "100%") %>%
visIgraphLayout(layout = "layout_with_fr") %>%
visNodes(font = list(color="black",size=40)) %>%
visOptions(highlightNearest = list(enabled = TRUE,labelOnly= FALSE, degree = 1, hover = TRUE),
nodesIdSelection = TRUE,
selectedBy = "group") %>%
visLegend(zoom=FALSE) %>%
visInteraction(dragView=FALSE,zoomView = TRUE,navigationButtons = TRUE, tooltipDelay = 120)