我可以为igraph中的根/终端顶点之间的edgelist属性创建单独的数据框吗? (R)

问题描述 投票:0回答:1

这是我正在处理的数据的负责人:

    motherinst                     inst      time      dist     speed
2  20080713_235233_es_0_JWC 20080714_163628_es_0_XKK 0.6971644 1.4921751 2.1403490
3  20080714_163628_es_0_XKK 20080715_160601_es_0_LAL 0.9788542 2.3070819 2.3569210
7  20080715_160601_es_0_LAL 20080716_153449_es_1_UOW 0.9783333 2.8299124 2.8925851
8  20080715_160601_es_1_CUA 20080716_153449_es_2_GOC 0.9783333 0.4322427 0.4418154
9  20080715_160601_es_2_KOE 20080716_153449_es_3_POU 0.9783333 4.1533350 4.2453168
10 20080715_160601_es_2_KOE 20080716_153449_es_4_SOA 0.9783333 2.1224896 2.1694954

我想要做的是能够指定一个根和终端顶点(通过#或“inst”),然后创建一个单独的数据框,其中每个单独的“dist”值在该根中所有顶点之间的行中向下运行 - 终端对。 Dist存储为edge属性。所以,基本上,我正在尝试制作所有这些顶点之间总距离的数据帧,每个顶点都存储在行中。

    JWC-XKK
1      0.69
2    .....
3    .....
r dataframe attributes root igraph
1个回答
0
投票

这是一些方法:

foo %>% 
  mutate_at(vars(1:2), ~str_sub(., start = -3)) %>% 
  select(motherinst, inst, weight = dist) %>% 
  mutate(weight = weight * 1.5)-> foo_graph

foo_graph

  motherinst inst   weight
1        JWC  XKK 2.238263
2        XKK  LAL 3.460623
3        LAL  UOW 4.244869
4        CUA  GOC 0.648364
5        KOE  POU 6.230003
6        KOE  SOA 3.183734

乘以1.5只是为了使顶点的宽度更加直观

library(igraph)

foo_plot <- graph.data.frame(foo_graph, directed = F)

plot(foo_plot, layout=layout_in_circle, edge.width = E(foo_plot)$weight, vertex.size = 30)

情节:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.