Learn R Programming

igraph (version 1.0.1)

layout_as_tree: The Reingold-Tilford graph layout algorithm

Description

A tree-like layout, it is perfect for trees, acceptable for graphs with not too many cycles.

Usage

layout_as_tree(graph, root = numeric(), circular = FALSE,
  rootlevel = numeric(), mode = "out", flip.y = TRUE)

as_tree(...)

Arguments

graph

The input graph.

root

The index of the root vertex or root vertices. If this is a non-empty vector then the supplied vertex ids are used as the roots of the trees (or a single tree if the graph is connected). If it is an empty vector, then the root vertices are automatically calculated based on topological sorting, performed with the opposite mode than the mode argument. After the vertices have been sorted, one is selected from each component.

circular

Logical scalar, whether to plot the tree in a circular fashion. Defaults to FALSE, so the tree branches are going bottom-up (or top-down, see the flip.y argument.

rootlevel

This argument can be useful when drawing forests which are not trees (i.e. they are unconnected and have tree components). It specifies the level of the root vertices for every tree in the forest. It is only considered if the roots argument is not an empty vector.

mode

Specifies which edges to consider when building the tree. If it is ‘out’, then only the outgoing, if it is ‘in’, then only the incoming edges of a parent are considered. If it is ‘all’ then all edges are used (this was the behavior in igraph 0.5 and before). This parameter also influences how the root vertices are calculated, if they are not given. See the roots parameter.

flip.y

Logical scalar, whether to flip the ‘y’ coordinates. The default is flipping because that puts the root vertex on the top.

...

Passed to layout_as_tree.

Value

A numeric matrix with two columns, and one row for each vertex.

Details

Arranges the nodes in a tree where the given node is used as the root. The tree is directed downwards and the parents are centered above its children. For the exact algorithm, the refernce below.

If the given graph is not a tree, a breadth-first search is executed first to obtain a possible spanning tree.

References

Reingold, E and Tilford, J (1981). Tidier drawing of trees. IEEE Trans. on Softw. Eng., SE-7(2):223--228.

See Also

Other graph layouts: add_layout_; as_bipartite, layout.bipartite, layout_as_bipartite; as_star, layout.star, layout_as_star; component_wise; in_circle, layout_in_circle; layout.auto, layout_nicely, nicely; layout.davidson.harel, layout_with_dh, with_dh; layout.gem, layout_with_gem, with_gem; layout.graphopt, layout_with_graphopt, with_graphopt; layout.grid, layout.grid.3d, layout.grid.3d, layout_on_grid, on_grid; layout.mds, layout_with_mds, with_mds; layout.merge, layout_components, merge_coords, piecewise.layout, piecewise.layout; layout.norm, norm_coords; layout.sugiyama, layout_with_sugiyama, with_sugiyama; layout_on_sphere, on_sphere; layout_randomly, randomly; layout_with_fr, with_fr; layout_with_kk, with_kk; layout_with_lgl, with_lgl; layout, layout_, print.igraph_layout_modifier, print.igraph_layout_spec; normalize

Examples

Run this code
# NOT RUN {
tree <- make_tree(20, 3)
plot(tree, layout=layout_as_tree)
plot(tree, layout=layout_as_tree(tree, flip.y=FALSE))
plot(tree, layout=layout_as_tree(tree, circular=TRUE))

tree2 <- make_tree(10, 3) + make_tree(10, 2)
plot(tree2, layout=layout_as_tree)
plot(tree2, layout=layout_as_tree(tree2, root=c(1,11),
                                           rootlevel=c(2,1)))
# }

Run the code above in your browser using DataLab