简体   繁体   中英

igraph in R, how to select edges based on incident vertex attributes?

I am looking for a way to subgraph edges based on a vertex attribute score of at least one of the vertices that are incident on that edge.

Is there an easy way to do so?

Any suggestions?

This question is missing a reproducible example or any example data of any kind. I'm going to take a risk and answer based on what I can guess Is being asked. First, I'll create a sample graph and assign arbitrary "prop" values to each vertex. I'll color them assuming i'm interested in prop>=3 and plot them.

library(igraph)

gg <- graph.atlas(711)
V(gg)$name <- 1:7
V(gg)$prop <- c(1,2,2,3,3,1,1)
V(gg)$color <- ifelse(V(gg)$prop>=3, "orange","yellow")
plot(gg)

全图

Now, I can find all the edges connected to a vertex with prop>=3 with

E(gg)[inc(V(gg)[prop>=3])]
# Edge sequence:
#            
# [3]  4 -- 3
# [4]  5 -- 4
# [5]  6 -- 5
# [10] 5 -- 3

And if I like I can extract those to a sub-graph with

g2 <- subgraph.edges(gg, E(gg)[inc(V(gg)[prop>=3])])
plot(g2)

子图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM