根据其他二分投影设置一个二分投影的边缘属性

问题描述

我正在用igraph中的二分投影和单模网络做一些工作。有没有一种方法可以使用另一个模式(下面的家乡网络)的顶点来标记一个模式下的网络(下面的艺术家网络)的边缘?

我想做类似下面的事情,但是担心随着艺术家节点数量的增加以及家乡之间的关系开始出现(例如,在两个小镇之间分配时间的艺术家),它不会扩展。

谢谢!

library(tibble)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter,lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect,setdiff,setequal,union
library(igraph)
#> 
#> Attaching package: 'igraph'
#> The following objects are masked from 'package:dplyr':
#> 
#>     as_data_frame,groups,union
#> The following object is masked from 'package:tibble':
#> 
#>     as_data_frame
#> The following objects are masked from 'package:stats':
#> 
#>     decompose,spectrum
#> The following object is masked from 'package:base':
#> 
#>     union

df <- tibble(user = c("Mac Miller","Wiz Khalifa","Arizona Zervas","Lil Wayne","Birdman","Logic"),hometown = c("Pittsburgh","Pittsburgh","DC","New Orleans","DC"))

g <- graph_from_data_frame(df) %>% 
    igraph::set_vertex_attr(.,name = "type",value = V(.)$name %in% df$hometown) %>% 
    bipartite_projection()

igraph::get.edgelist(g$proj1)
#>      [,1]             [,2]         
#> [1,] "Mac Miller"     "Wiz Khalifa"
#> [2,] "Arizona Zervas" "Logic"      
#> [3,] "Lil Wayne"      "Birdman"

g1 <- igraph::set.edge.attribute(graph = g$proj1,name = "hometown",value = get.vertex.attribute(g$proj2)$name)

get.edgelist(g1)
#>      [,] "Lil Wayne"      "Birdman"

get.edge.attribute(g1)
#> $weight
#> [1] 1 1 1
#> 
#> $hometown
#> [1] "Pittsburgh"  "DC"          "New Orleans"

reprex package(v0.3.0)于2020-08-19创建

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...