圆形包装代表一个层次:最大的圆(层次的原点)包含几个大圆(第1层的节点),其中包含较小的圆(第2层)等等。最后一层称为叶子。
输入数据是节点之间的边列表。它应该看起来或多或少像旁边的桌子。此外,我们通常将此表与另一个为每个节点提供特征的表一起提供。
最基本的圆形包装ggraph
该ggraph
软件包使从边缘列表构建圆形包装变得轻而易举。这是一个基于flare
包提供的数据集的示例。
第一步是借助包的graph_from_data_frame()
功能将数据框转换为图形对象igraph
。然后,ggraph
提供geom_node_circle()
将构建图表的功能。
# Libraries
library(ggraph)
library(igraph)
library(tidyverse)
# We need a data frame giving a hierarchical structure. Let's consider the flare dataset:
edges <- flare$edges
# Usually we associate another dataset that give information about each node of the dataset:
vertices <- flare$vertices
# Then we have to make a 'graph' object using the igraph library:
mygraph <- graph_from_data_frame( edges, vertices=vertices )
# Make the plot
ggraph(mygraph, layout = 'circlepack') +
geom_node_circle() +
theme_void()
摘自:https://r-graph-gallery.com/313-basic-circle-packing-with-several-levels.html