require(igraph)
gr <- graph_from_data_frame(flare$edges, vertices = flare$vertices)
ggraph(gr, 'treemap', weight = 'size') + geom_treemap()
# We can color by modifying the graph
gr <- treeApply(gr, 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
})
ggraph(gr, 'treemap', weight = 'size') +
geom_treemap(aes(fill = Class, filter = leaf, alpha = depth), colour = NA) +
geom_treemap(aes(size = depth), colour = 'white') +
scale_alpha(range = c(1, 0.5), guide = 'none') +
scale_size(range = c(4, 0.2), guide = 'none')
Run the code above in your browser using DataLab