2017-03-16 66 views
1

我有一个图G =(V,E),其中有几个属性,包括边权重属性。我试图根据权重高于x的条件创建子图。基于边权重的子集图

我试过了标准R子集选项g <- E(g)[weight > max(weight)*.10],但我总是得到一个向量。 我不知道我在做什么错在这里。

回答

5

也许你想这样的事情

library(igraph) 
set.seed(1) 
m <- matrix(sample(c(.5, 2, 5), 100, replace=T, prob = c(.6,.3,.1)), nc=10, dimnames = rep(list(letters[1:10]), 2)) 
g <- graph_from_adjacency_matrix(m, weighted=T, diag=F, mode="undirected") 
coords <- layout.auto(g) 
par(mfrow = c(1,3)) 

plot(g, layout=coords, edge.width = E(g)$weight) 

s1 <- subgraph.edges(g, E(g)[E(g)$weight>2], del=F) 
plot(s1, layout=coords, edge.width = E(s1)$weight) 

s2 <- delete_vertices(s1, degree(s1, mode = "in")==0) 
plot(s2, layout=coords[V(g)$name%in%V(s2)$name,], edge.width = E(s2)$weight) 

enter image description here

+0

我没有流矩阵,但是你的代码实际上回答了我的问题。我没有使用subgraph.edges函数,并且确实没有delete_vertices。 谢谢。 – FilipeTeixeira

0

这将是因为你只子集的边缘取代你的图g。如果你想删除低于阈值权重的边缘,你可以使用:

g_sub <- delete.edges(g, E(g)[weight <= max(weight)*.10])