R 基于边权的子集图

R 基于边权的子集图,r,igraph,R,Igraph,我有一个图,G=(V,E)有几个属性,包括边权重属性。我试图创建一个基于权重大于x的条件的子图 我用gmax(weight)*.10]尝试了标准的R子集选项,但我总是得到一个向量。 我不确定我做错了什么。也许你想要这样的东西 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:

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

我用
gmax(weight)*.10]
尝试了标准的R子集选项,但我总是得到一个向量。
我不确定我做错了什么。

也许你想要这样的东西

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)
库(igraph)
种子(1)

也许你想要这样的东西

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)
库(igraph)
种子(1)

m那是因为你用子集边替换了图g。如果要删除阈值权重以下的边,可以使用:

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

g_sub这是因为您将图形g替换为仅子集边。如果要删除阈值权重以下的边,可以使用:

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

g_sub我没有流矩阵,但是你的代码实际上回答了我的问题。我没有使用subgraph.edges函数,也没有使用delete_顶点函数。谢谢。我没有流矩阵,但是你的代码实际上回答了我的问题。我没有使用subgraph.edges函数,也没有使用delete_顶点函数。非常感谢。