1

我有以下tidygraph 标题

rstat_nodes <- data.frame(name = c("Hadley", "David", "Romain", "Julia"), sex = c("M","M","M","F"))
rstat_edges <- data.frame(from = c(1, 1, 1, 2, 3, 3, 4, 4, 4), 
                            to = c(2, 3, 4, 1, 1, 2, 1, 2, 3))
g <- tbl_graph(nodes = rstat_nodes, edges = rstat_edges)
g

它看起来像这样:

> g
# A tbl_graph: 4 nodes and 9 edges
#
# A directed simple graph with 1 component
#
# Node Data: 4 x 2 (active)
  name   sex  
  <fct>  <fct>
1 Hadley M    
2 David  M    
3 Romain M    
4 Julia  F    
#
# Edge Data: 9 x 2
   from    to
  <int> <int>
1     1     2
2     1     3
3     1     4
# … with 6 more rows

有没有一种方便的方法可以将它们分成两个纯小块,一个用于节点部分,另一个用于边缘部分。

4

1 回答 1

1

我对 tidygraphs 比较陌生。看看数据结构是什么样的很有趣,但也许这就是你要找的?

# to get nodes
g %>% activate(nodes) %>% as_tibble()
# to get edges
g %>% activate(nodes) %>% as_tibble()
于 2019-10-25T09:32:24.220 回答