BasicTreePlots
Documentation for BasicTreePlots.
This is a package that aims to provide generic plotting recipes for tree like data structures. As such the recipes should only require that your data structure fulfills the AbstractTrees interface, i.e. has AbstractTrees.children(YourType)
defined.
Optionally, BasicTreePlots.distance(YourType)
and BasicTreePlots.label(YourType)
can be defined to allow plotting trees with variable distances between children and parent nodes and pretty printing of each node in the tree respectively.
Currently, we only provide Makie.jl
backends, but are interested in contributions for recipes for Plots.jl
and TidyPlots.jl
. As well as any other backends or custom tree structures that don't work automatically. See the ext
folder for example extensions.
Installation
using Pkg
Pkg.add("BasicTreePlots")
Or the development version with
using Pkg
Pkg.add("https://github.com/BenjaminDoran/BasicTreePlots.jl.git")
Basic usage
using CairoMakie, BasicTreePlots
tree = ((:a, :b), (:c, :d))
treeplot(tree)
see Tutorials and Gallery for more in depth examples
treeplot()
documentation
see reference for other function's documentation
BasicTreePlots.treeplot
— Functiontreeplot(tree; kwargs...)
Args:
- tree, the root node of a tree that has
AbstractTrees.children()
defined. All nodes should be reachable by usingAbstractTrees.PreOrderDFS()
iterator.
Keyword arguments:
showroot::Bool = false
, ifBasicTreePlots.distance()
is notnan
for root, show line linking root to parent.layoutstyle::Symbol = :dendrogram
available options are:dendrogram
, or:cladogram
:dendrogram
displays tree taking into account the distance between parent and children nodes as calculated fromBasicTreePlots.distance(node)
. If the distance is not defined, it defaults to1
and is equivalent to the:cladogram
layout:cladogram
displays the tree where each distance from a child node to their parent is set to1
.
branchstyle::Symbol = :square
available options are:square
or:straight
:square
will display line from child to parent as going back to the height of the parent, before connecting back to the parent node at a right angle.straight
will display line from child to parent as a straight line from child to parent.
linecolor = :black
, should match thecolor
option in Makie'slines
plot. Can be either a single color:black
, color plus alpha transperency(:black, 0.5)
, or a vector of numbers for each node in pre-walk order. color for each node is associated to the line connecting it to its parent.linewidth = 1
, should match thelinewidth
option in Makie'slines
plot. Can be either a single width or a vector of numbers for each node in pre-walk order. width for each node is associated to the line connecting it to its parent.linecolormap=:viridis
color map associated tolinecolor
. can be symbel of known colormap or gradient created fromcgrad()
. see Makie's color documentationbranch_point_resolution = 25
, number of points associated to each line segment. Can be decreased to increase plotting speed. Or, increased if lines that should be smooth are not.usemaxdepth = false
, iftrue
draw guide lines from each leaf tip to the depth of the leaf that is maximally distant from root. Useful for connecting leaves to there location on the y axis (or θ axis if plotted onPolarAxis
).tipannotationsvisible::Bool = true
, whether to show text labels for each leaf tip.tipfontsize = 9.0f0
, font size that tip labels are displayed at.openangle = 0
, Angle in radians that limits span of tree around the circle when plotted onPolarAxis
. ifopenangle = deg2rad(5)
then leaf tips will spread across angles0
to(2π - openangle)
.tipalign = (:left, :center)
text alignment of tip labels. see Makie optionstipannotationoffset = (3.0f0, 0.0f0)
offset of tip label from actual tip position. The first value is associated with thex
axis, and the second is associated with they
axis. (Currently, only available for cartisian axis)