Dario Federici
Dario Federici

Reputation: 1258

R Igraph subgraph given node index and number of nodes to include in the graph

I want to plot a portion of a graph according to a specific node and ideally a distance from that node or a number of nodes as part of the sub graph.

The data.frame that I am graphing is as follows:

Column 1   Column 2   Sequence
   A          B           1
   A          D           2
   D          B           3
   Z          E           4
   E          D           5

this is the code:

network <- graph.data.frame(data_to_graph[,c(1,2)])

subnetwork <- induced.subgraph(network, vids = 30, impl = 'copy_and_delete', eids = c(5,6,7,8,9,10,11,12,13,14,15))

plot(subnetwork)

I would like, by specifying an element of column 1 to plot a graph at a certain distance from that node.

Thanks

Dario.

Upvotes: 1

Views: 561

Answers (1)

Dario Federici
Dario Federici

Reputation: 1258

This is the answer:

distan <- 3
node <- "node name"

subnetwork <- induced.subgraph(network, vids = as.vector(unlist(neighborhood(network, distan, nodes = node, mode = 'all'))))

plot.igraph(subnetwork, vertex.size=10)

Upvotes: 1

Related Questions