wake_wake - 9 days ago 5

R Question

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

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