How can i plot binary tree with 13 nodes in R Studio
plot, r
Solution
You can use `graph.tree` function, e.g. :
library(igraph)
G <- graph.tree(n=13,children=2)
# let's print it using a tree-specific layout
# (N.B. you must specify the root node)
co <- layout.reingold.tilford(G, params=list(root=1))
plot(G, layout=co)
EDIT (as per comment) :
library(igraph)
G <- graph.tree(n=13,children=2)
#add names to vertex (just assign a upper-case letter to each)
V(G)$name <- LETTERS[1:length(V(G))]
# plot (1)
lay <- layout.reingold.tilford(G, params=list(root='A'))
plot(G, layout=lay, vertex.size=25)
# add a vertex 'O', then a new edge 'G' --> 'O'
G <- G + vertices('O')
G <- G + edge('G', 'O')
# plot again (2)
lay <- layout.reingold.tilford(G, params=list(root='A'))
plot(G, layout=lay, vertex.size=25)
Problem
I am new in R , i plot graph like ring, star. There are special functions for them, but i dont have any idea how can i plot a binary tree with 13 nodes? I used graph.extended.chordal.ring() function but it didnt help. Is there any good tutorial for R studio and how can i plot a binary tree? ``` library(igraph) G <- graph.extended.chordal.ring(13, matrix(c(2,4,6), nr=1)) L <- layout.fruchterman.reingold(G) ```