# Create a graph of the flare class system
library(igraph)
flareGraph <- graph_from_data_frame(flare$edges, vertices = flare$vertices)
importFrom <- match(flare$imports$from, flare$vertices$name)
importTo <- match(flare$imports$to, flare$vertices$name)
flareGraph <- treeApply(flareGraph, function(node, parent, depth, tree) {
tree <- set_vertex_attr(tree, 'depth', node, depth)
if (depth == 1) {
tree <- set_vertex_attr(tree, 'class', node, V(tree)$shortName[node])
} else if (depth > 1) {
tree <- set_vertex_attr(tree, 'class', node, V(tree)$class[parent])
}
tree
})
V(flareGraph)$leaf <- degree(flareGraph, mode = 'out') == 0
# Use class inheritance for layout but plot class imports as bundles
ggraph(flareGraph, 'dendrogram', circular = TRUE) +
geom_edge_bundle(aes(colour = ..index..), data = gCon(importFrom, importTo),
edge_alpha = 0.25) +
geom_node_point(aes(filter = leaf, colour = class)) +
scale_edge_colour_distiller('', direction = 1, guide = 'edge_direction') +
coord_fixed() +
ggforce::theme_no_axes()
Run the code above in your browser using DataLab