【问题标题】:Color nodes in directed network in RR中有向网络中的颜色节点
【发布时间】:2020-10-06 03:07:13
【问题描述】:

我有一个只有两种类型节点的有向网络,A 和 B。方向总是从任何给定的 A到任何给定的 B。没有其他方向是可能的。

边缘列表如下所示:

edges <- read.table(text = " from to weight 1 6 1.2 3 7 1.4 4 6 1.2 1 7 1.2 2 8 1.2 1 9 1.2 5 10 1.2 ", header=T )

节点列表如下所示:

nodes
id 
1  1   
2  1   
3  3  
4  4   
5  5  
6  6    
7  7    
8  B
9  9
10 10


图表是使用 igraph 包创建的。

g <- graph_from_data_frame(d = edges, vertices=nodes, directed = TRUE)

是否可以根据边缘列表中的对节点进行着色,而不向节点列表添加其他变量/标签?

(我尝试过像这样为节点着色,但意识到这没有多大意义)

plot(g, vertex.color=V(g$edges=='from'))

【问题讨论】:

  • 在您的示例中,6 属于“从”和“到”类别,对于 7 也是如此。
  • @desval 谢谢,我更正了。

标签: r igraph


【解决方案1】:

我不是 100% 确定,但我认为您正在寻找的东西并不真正存在。 vertex.color 需要一个颜色向量,每个顶点一种颜色。

同时,作为一种变通方法,您可以使用 degree 的输出来选择入(或出)度为 0 或更高的顶点:

plot(g,
     vertex.color=ifelse(degree(g, mode = "out")>0, "red", "black"),
     size=15)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-17
    相关资源
    最近更新 更多