Directed will be plugged from kg table’s directed column.
Visualising the knowledge graph
Click to view code
set.seed(1234)
This is to ensure reproducibility. ## Visualising the Whole Graph
Click to view code
ggraph(graph, layout ="fr") +geom_edge_link(alpha =0.3, # line, alpha is transparency colour ="gray") +geom_node_point(aes(color =`Node Type`), # point (plot after line so that it doesn't get covered by line)size =4) +# size of point geom_node_text(aes(label = name), # label using namerepel =TRUE, # prevent overlapping names, force words apartsize =2.5) +theme_void()
Visualising the sub-graph
In this section, we are interested to create a sub-graph base on MemberOf vaue in Edge Type column of the edges data frame.
Step 1: Filter edges to only “Memberof”
Click to view code
graph_memberof <- graph %>%activate(edges) %>%# Focus on edges tablefilter(`Edge Type`=="MemberOf") # Filter to MemberOf
Step 2: Extract only connected nodes (i.e., used in these edges)
Click to view code
used_nodes_indices <- graph_memberof %>%activate(edges) %>%as_tibble() %>%select(from,to) %>%# Only selected variablesunlist() %>%# because it is a graph model, not a listunique()