考虑这个简单的例子
mynodes_alt <- tibble(id = c(1,2,4,5),
mygroup = c(2,2,3,3))
myedges_alt <- tibble(from = c(1,1,4),
to = c(4,2,3),
power = c(3,3,3))
tbl_graph(nodes = mynodes_alt, edges = myedges_alt)
# A tbl_graph: 4 nodes and 3 edges
#
# A rooted tree
#
# Node Data: 4 x 2 (active)
id mygroup
<dbl> <dbl>
1 1 2
2 2 2
3 4 3
4 5 3
#
# Edge Data: 3 x 3
from to power
<int> <int> <dbl>
1 1 4 3
2 1 2 3
3 4 3 3
如您所见,这里只有 3 条边。但是,创建网络即会ggraph
生成一个令人费解的图表。
tbl_graph(nodes = mynodes_alt, edges = myedges_alt) %>%
ggraph(layout = 'grid') +
geom_node_point(aes(color = factor(mygroup))) +
geom_edge_arc(aes(alpha = power, label = power)) +
geom_node_text(aes(label = id), repel = TRUE) +
theme_graph()
到底是怎么回事?那个节点 5 来自哪里?它应该没有边缘。
谢谢!