p <- c('knitr','tidyverse', 'igraph', 'tidygraph', 'ggraph', 'visNetwork', 'lubridate', 'ggrepel', 'magrittr')
lapply(p, require, character.only = TRUE)
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))
g<- GAStech_graph %>%
mutate(betweenness_centrality = centrality_betweenness()) %>%
mutate(closeness_centrality = centrality_closeness())
qgraph(
g,
node_colour = closeness_centrality,
node_size = betweenness_centrality
)
Utilised qgraph() to ensure a cleaner node and creating a standard network plot for explorative purpose.
| No. | Problems | Solutions |
|---|---|---|
| 1. | Edges are too dark. | We can play around with the opacity to tone it down. |
| 2. | Nodes sizes are too small. | Increase their sizes. |
| 3. | There are too many missing information | Include labels such as job title and department. |
Sketch 1
graphData <- GAStech_graph %>%
mutate(betweenness_centrality = centrality_betweenness()) %>%
mutate(closeness_centrality = centrality_closeness())
g<-ggraph(graphData) +
geom_edge_link(aes(colour = Weekday))
g + geom_edge_density(aes(fill= Weight),strength = 0.5)+
geom_node_circle(aes(fill = closeness_centrality, r = log(betweenness_centrality)/100, col = Department), size = 2) +
geom_node_label(aes(label = label), colour = "black", size = 1.5, repel = TRUE)
With reference to the organisation network graph in Section 7.4 of Hands-on Exercise 10, you are required to complete the following tasks:
When a name is selected from the drop-down list, the corresponding node will not only be highlighted but also will be labelled. Furthermore, all the linked nodes of the selected node will also be labelled too. When a node of the interactive graph is selected, the node will not only be highlighted but also will be labelled. Furthermore, all the linked nodes of the selected node will be labelled as well.
################### Data Prep #####################
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)
| No. | Problems | Solutions |
|---|---|---|
| 1. | Users can only filter by ID. | Allow for more dimensions to analyze the graph such as filtering by Group. Input tooltip to display JobTitle. |
| 2. | There are too many overlapped edges which makes relatioship between specific nodes hard to spot. | Allow user to drag nodes such that they can have the flexibility to rearrange and analyze specific nodes and input highlighted features. |
| 3. | No legends being shown. | Input legends so that user can better comprehend the graph. |
| 4. | It is hard to interact with the graph. | Input navigation buttons so that user can better control the view of the graph. |
| 5. | Weights are not shown | Instead of displaying tooltips at the edges, allow tooltip to be seen when user hover over the edges. This will prevent cluttering of data. |
Sketch 2
################### Data Prep #####################
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)
GAStech_nodes$shape = "circle"
GAStech_nodes$title <- paste0("<p>Job Title: ",GAStech_nodes$Title,"</p>")
GAStech_edges_aggregated$label <- GAStech_edges_aggregated$value
GAStech_edges_aggregated$title <- paste0("<p>Weight: ",GAStech_edges_aggregated$weight,"</p>")
visNetwork(GAStech_nodes, GAStech_edges_aggregated, height = "700px", width = "100%") %>%
visIgraphLayout(layout = "layout_with_fr") %>%
visOptions(manipulation = TRUE,selectedBy = "group", highlightNearest = list(
degree = list(from = 1, to = 1), enabled = TRUE, labelOnly = TRUE, hover = TRUE),nodesIdSelection = TRUE)%>%
visPhysics(stabilization = FALSE)%>%
visEdges(arrows = list(
to = list(enabled = TRUE),
from = list(enabled = TRUE)
)) %>%
visLegend()%>%
visInteraction(navigationButtons = TRUE,hover = TRUE, multiselect = TRUE,tooltipDelay = NULL, tooltipStyle = 'position: fixed;visibility:hidden;padding: 2px;white-space: nowrap;
font-family: verdana;font-size:12px;font-color:white;background-color:brown;', tooltipStay = 300, zoomView = TRUE)