R - 使用顶点属性 igraph 创建新的图形对象
R - Make new graph object using vertex attribute igraph
我有一个有向图对象,其中两列用于节点(id、类型),两列用于边(from、to)。有没有一种简单的方法来获取将类型设为顶点所产生的图形?
顶点:
id type
1 a
2 a
3 b
4 c
边:
from to
1 2
2 4
3 4
1 3
转换为:
顶点:
id type
a a
b b
c c
边:
from to
a a
a c
b c
a b
我用这段代码制作图表得到上面的第一个图表对象:
nodes <- read.csv("1.toyNODES.CSV", header=T, as.is=T)
edges <- read.csv("1.toyEDGES.CSV", header=T, as.is=T)
graph <- graph_from_data_frame(d=edges, vertices=nodes, directed=T)
这将聚合组之间的边:
type.factor <- as.factor(V(your.g)$type)
type <- as.numeric(type.factor)
meta.g <- contract.vertices(your.g,type)
E(meta.g)$weight <- 1
meta.g <- simplify(meta.g)
Kolaczyk / Csardi
我有一个有向图对象,其中两列用于节点(id、类型),两列用于边(from、to)。有没有一种简单的方法来获取将类型设为顶点所产生的图形?
顶点:
id type
1 a
2 a
3 b
4 c
边:
from to
1 2
2 4
3 4
1 3
转换为:
顶点:
id type
a a
b b
c c
边:
from to
a a
a c
b c
a b
我用这段代码制作图表得到上面的第一个图表对象:
nodes <- read.csv("1.toyNODES.CSV", header=T, as.is=T)
edges <- read.csv("1.toyEDGES.CSV", header=T, as.is=T)
graph <- graph_from_data_frame(d=edges, vertices=nodes, directed=T)
这将聚合组之间的边:
type.factor <- as.factor(V(your.g)$type)
type <- as.numeric(type.factor)
meta.g <- contract.vertices(your.g,type)
E(meta.g)$weight <- 1
meta.g <- simplify(meta.g)
Kolaczyk / Csardi