简体   繁体   中英

Degrees in I graph

I am a Newbie in I-graph. I wish to know.

  1. How to isolate nodes with a specific degree value?
  2. How to know their node IDs
  3. Can we draw a new graph with degrees above the given thresholds. Say nodes graph with nodes > n?

If there is any more tutorial/book with a more involved treatment of degree function, please let me know

Warm Regards

SHRINIVAS

I think you can use the vertex function V() , degree() , and base R functions like which() to get what you want. See below.

library(igraph)

set.seed(12345)
                                        # Generate a graph with a heterogeneous degree distribution
g <- sample_fitness_pl(
    no.of.nodes = 200,
    no.of.edges = 1000,
    exponent.out = 2
)
                                        # Plot to confirm
plot(g, vertex.label = "", vertex.size = 2)
                                        # Collect the degree sequence
k_i <- degree(g)
                                        # And the distinct observed degrees
k_bins <- sort(unique(k_i))
                                        # Plot the degree histogram
hist(k_i, breaks = 20)
                                        # Let's look at nodes with k_i = 10
n <- 10
                                        # We can use the base R function `which()` to return the node
                                        # IDs of those nodes with k_i = n
V(g)[which(k_i == n)]
## [1] 126 134 145 154

I think for (3) you want an induced subgraph with only those nodes with k_i > n. However, in the induced subgraph, those nodes will not necessarily have the same degree as in the original graph. If that isn't quite what you're looking for, see the manual here to see if there's a better option.

                                        # These are the nodes with k_1 >= n
plot(g, vertex.label = "", vertex.size = 2, vertex.color = ifelse(k_i > n, 2, 1))

h <- induced_subgraph(
    g,
    vids = V(g)[which(k_i >= n)]
)

plot(h, vertex.label = "", vertex.size = 3, vertex.color = 2)

For books, you might try this one .

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