Click to view code
::p_load(jsonlite, tidyverse, SmartEDA, tidygraph, ggraph) pacman
Li Jianyi
May 17, 2025
The three challenges from VAST 2025.
This in-class exercise challenge is Mini-Challenge 1.
In the code chunk below, p_load() of pacman package is used to load the R packages into R environment.
In the code chunk below, fromJSON()
of jsonlite package is used to import MC1_graph.json file into R and save the output object.
This ensures each id from node list is mapped to the correct number.
The number of observations in edges_tbl should be the same as before running this code chunk.
Before doing leftjoin, there are only 4 variables. AFter doing the leftjoin, there is two additional variables.
This will get rid of any missing values.
Lastly, tbl_graph()
is used to create tidygraph’s graph object by using the code chunk below.
Directed will be plugged from kg table’s directed column.
This is to ensure reproducibility. ## Visualising the Whole Graph
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 name
repel = TRUE, # prevent overlapping names, force words apart
size = 2.5) +
theme_void()
In this section, we are interested to create a sub-graph base on MemberOf vaue in Edge Type column of the edges data frame.
This is to eliminate orphan nodes.