Description Usage Arguments Details Examples
View source: R/reduce_nodes_to_focus.R
There is the option to select all nodes linked to the set of key nodes within a certain number of steps, or only in one direction
1 | reduce_nodes_to_focus(startmat, maxdist, keynodes, tofrom)
|
startmat |
the starting adjacency matrix (NOT an igraph object), to be reduced |
maxdist |
the greatest distance (in terms of the number of links traversed) at which a node is considered connected to the key nodes |
keynodes |
the set of key nodes (e.g., c(1,5,9)) |
tofrom |
choice between keeping nodes that are (1) linked towards the key nodes, 'to', (2) linked away from the key nodes, 'from', or (3) either to or from, 'either' |
Created 2020-05-29
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | j <- matrix(rbinom(n=100,p=0.1,size=1),nrow=10)
diag(j) <- 0
jnames <- letters[1:10]
library(igraph)
ji <- graph_from_adjacency_matrix(j)
V(ji)$names <- jnames
plot.igraph(ji, vertex.label=V(ji)$names, vertex.color='light green', main='Starting matrix')
jout <- reduce_nodes_to_focus(startmat=j, maxdist=2, keynodes=c(1,5), tofrom='to')
jouti <- graph_from_adjacency_matrix(jout$outmat)
V(jouti)$names <- jnames[jout$keepers]
plot(jouti, vertex.label=V(jouti)$names, vertex.color='light green', main='2 steps TO key nodes 1 and 5')
jout2 <- reduce_nodes_to_focus(startmat=j, maxdist=2, keynodes=c(1,5), tofrom='from')
jout2i <- graph_from_adjacency_matrix(jout2$outmat)
V(jout2i)$names <- jnames[jout2$keepers]
plot(jout2i, vertex.label=V(jout2i)$names, vertex.color='light green', main='2 steps FROM key nodes 1 and 5')
jout3 <- reduce_nodes_to_focus(startmat=j, maxdist=2, keynodes=c(1,5), tofrom='either')
jout3i <- graph_from_adjacency_matrix(jout3$outmat)
V(jout3i)$names <- jnames[jout3$keepers]
plot(jout3i, vertex.label=V(jout3i)$names, vertex.color='light green', main='2 steps TO OR FROM key nodes 1 and 5')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.