Harvey Kristanto Lauw
17 November 2019
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:
Improve the code chunk used to create the organisation network graph by using the latest functions provided in ggraph2.0.
Identify three aspects of the graph visualisation in Section 6.1 that can be improved.
Provide the sketch of your alternative design.
Using appropriate ggraph functions, plot the alternative design.
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()
Sketch
set_graph_style()
g <- GAStech_graph %>%
mutate(betweenness_centrality = centrality_betweenness()) %>%
mutate(closeness_centrality = centrality_closeness()) %>%
ggraph(layout = "circle") +
geom_node_voronoi(aes(fill = Department), max.radius = 0.5, colour = 'white') +
geom_edge_density(aes(fill = Weight)) +
geom_edge_link(aes(width = Weight), alpha = 0.1) +
geom_node_point(aes(color = closeness_centrality, size = betweenness_centrality))
g + theme_graph() + facet_edges(~Weekday) + theme(legend.position = "bottom", legend.direction = "vertical")
## nerror = 4
## Increasing madj from 23 to 28 and trying again.
## nerror = 4
## Increasing madj from 28 to 34 and trying again.
## nerror = 4
## Increasing madj from 23 to 28 and trying again.
## nerror = 4
## Increasing madj from 28 to 34 and trying again.
## nerror = 4
## Increasing madj from 23 to 28 and trying again.
## nerror = 4
## Increasing madj from 28 to 34 and trying again.
## nerror = 4
## Increasing madj from 23 to 28 and trying again.
## nerror = 4
## Increasing madj from 28 to 34 and trying again.
## nerror = 4
## Increasing madj from 23 to 28 and trying again.
## nerror = 4
## Increasing madj from 28 to 34 and trying again.
With reference to the organisation network graph in Section 7.4 of Hands-on Exercise 10, you are required to complete the following tasks:
Improve the design of the graph by incorporating the following interactivity:
Identify three aspects of the graph visualisation in Section 7.4 that can be improved.
Provide the sketch of your alternative design.
Using appropriate visNetwork functions, plot the alternative design.
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)
Sketch
visNetwork(GAStech_nodes, GAStech_edges_aggregated) %>%
visIgraphLayout(layout = "layout_in_circle") %>%
visInteraction(dragNodes = TRUE, dragView = TRUE,zoomView = TRUE,navigationButtons=TRUE) %>%
visNodes(shape = "box" ,
shadow = list(enabled = TRUE,
size = 20),
font = "16px arial black") %>%
visEdges(arrows = "to" ,
selectionWidth = 8,
shadow = FALSE,
color = list(highlight = "Red")) %>%
visOptions(highlightNearest = list(enabled = TRUE,
hover = TRUE,
algorithm = "hierarchical"),
nodesIdSelection = list(enabled = TRUE,
values = unique(GAStech_nodes$id)))