igraph并尝试获取群集中节点的名称

时间:2018-01-30 14:41:55

标签: networking cluster-computing nodes igraph

我有一个网络(Ex: A->B , B->C , J->K, etc)因此有些网络会像A一样连接到BC,而有些只有J到{{1}的链接}}。我使用igraph(K)创建了我的网络。我使用get_graph_from_data_frame来查看存在多少个单独的集群以及每个集群中有多少个节点。我希望得到那些节点的名称。反正有没有这样做?我只想知道有多少只连接到另一个节点或有多少连接到2节点。

这是我的代码:

clusters()$csize

我有多少个集群和每个节点。是否有一个函数可以从每个集群中提取这些节点名称?

1 个答案:

答案 0 :(得分:0)

您不提供数据,因此我提供了一个非常简单的图表作为示例。

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://n 
<id>snapshot</id>
<formats>
   <format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
   <dependencySet>
      <outputDirectory>/</outputDirectory>
      <useProjectArtifact>true</useProjectArtifact>
      <unpack>true</unpack>
      <scope>test</scope>
   </dependencySet>
</dependencySets>
<fileSets>
   <fileSet>
      <directory>${project.basedir}</directory>
      <outputDirectory>/</outputDirectory>
      <includes>
         <include>**/*.class</include>
         <include>**/*.properties</include>
         <include>**/*.*</include>
      </includes>
      <useDefaultExcludes>true</useDefaultExcludes>
   </fileSet>
</fileSets>
</assembly>

Network with 2 components

现在我们可以获得您想要的组件。

library(igraph)

relations <- data.frame(from=c("Bob", "Cecil", "Cecil", "David",
                               "David", "Esmeralda", "Tom", "Tom"),
                        to=c("Alice", "Bob", "Alice", "Alice", "Bob", 
                    "Alice", "Dick", "Harry"))
g <- graph_from_data_frame(relations)
plot(g)
相关问题