# Lineage tree plots

I am trying to plot a lineage tree, for example:

This plot represents a population of dividing cells. Each horizontal line is the lifetime of a single cell, until division. When it divides, the line branches into the two lines of the daughter cells. Note that different cells might have different times of division, therefore horizontal lines have different lengths.

I don't have the dataset behind this plot. But you can assume that it consists of a list of cells, where each cell carries the information of its parent, and its division time.

You can use Dendrogram to create such a plot (even though it's not quite meant for that).

First, we need to build the corresponding tree graph, and add the division time of the cell as the VertexWeight. Then simply apply Dendrogram.

Suppose that cells are represented by sequential integers, and divisions are given in the format {cell, time}.

data = {
{0, 0}, (* cell 0 divides at time 0 to create cells 1 and 2 *)
{1, 0.1}, (* cell 1 divides at time 0.1 to create cells 3 and 4 *)
{3, 0.25} (* cell 3 divides at time 0.25 to create cells 5 and 6 *)
};


Compute the edges of the graph:

edges = Catenate@Module[{c = 0},
{First[#] -> ++c, First[#] -> ++c} & /@ data
]


Add the "vertex weights", representing the division times. I manually assigned time 1.0 to cells that are still not divided at the end of the dataset.

weights =
Lookup[
Association[Rule @@@ data],
VertexList[edges],
1.0 (* end time *)
]


If any cells die before the end time (as it looks like in your example plot), you would need to assign the appropriate death time for them.

Build the tree graph:

tree = TreeGraph[edges, VertexWeight -> weights,
GraphLayout -> "LayeredDigraphEmbedding",
VertexLabels -> "Name"]


Draw the dendrogram:

Dendrogram[tree, Right,
Frame -> True, FrameTicks -> {Automatic, None},
FrameLabel -> {"Evolutionary time", None},

• Thanks, this is very useful. I only missed one point. You say: If any cells die before the end time (as it looks like in your example plot), you would need to assign the appropriate death time for them. I am not sure how to do that. – becko Dec 28 '17 at 14:29
• @becko The weights list contains the times at which each cell is drawn. Simply add the appropriate time. E.g. add the times to the association Association[Rule @@@ data] like this: Association[Rule @@@ data, {4 -> 0.8]. This causes node 4 to be drawn at time 0.8. – Szabolcs Dec 28 '17 at 15:11
• Missing a } above, but I hope that's clear. Also, unfortunately I do not think Dendrogram is able to draw complex trees as space efficiently as your example. It won't overlap parts even when it would be possible. – Szabolcs Dec 28 '17 at 17:25