Skip to content

Instantly share code, notes, and snippets.

@sotelo
Created May 19, 2015 04:21
Show Gist options
  • Save sotelo/d61ce55bd27ad2032449 to your computer and use it in GitHub Desktop.
Save sotelo/d61ce55bd27ad2032449 to your computer and use it in GitHub Desktop.
grafica arbol
library("igraph")
num_layer = 7
num_nodes = (num_layer+1)*num_layer/2
M <-matrix(rep(0,num_nodes*num_nodes),nrow=num_nodes,ncol=num_nodes)
layout <- matrix(rep(0, 2*num_nodes), nrow=num_nodes)
node = 0
for(layer in 1:num_layer){
for(rel_node in 1:layer){
node = node+1
if(layer < num_layer) {
M[node, node + layer] = 1
M[node, node + layer + 1] = 1
}
layout[node, 1] = layer
layout[node, 2] = 0.5*layer - rel_node + 0.5
}
}
layout
g = graph.adjacency(M)
plot(g, layout = layout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment