wake_wake wake_wake - 1 year ago 115
R Question

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?

Answer Source

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.


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")

full graph

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

# 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])])


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download