[Tex/LaTex] Rich phylogenetic trees accompanied with a non-linear timeline

newicktreetikz-treestrees

I wish to draw a phylogenetic tree which is graphically rich (the edges may have several colours/styles), and more importantly, the tree would be aligned with a timeline, which need not be linear.

The closest example I could find to what I was looking for is the following:

enter image description here

Taken from here.

The animal pictures on the right are nice, but I do not really care about these. The colour bars are also nice, but again, not of significant importance. The two elements in this picture that I would like to have are the dashed line, and the timeline (which is implemented here as vertical white bars with a label at the bottom). Since the labels seem custom, I can make the timeline "non-linear". I also find it useful to control the font of the animal labels (as they did in the picture with dog).

I first thought that the newicktree package should do the job, but after reading its documentation, it seems rather simple, and probably incapable for such a task. The next guess would be tikz, but I have less experience with it, and it has quite a lot of packages. Do you think any of these fits such a task?

Just to make it clear, I am only interested in being able to produce the result, I do not care much about the syntax needed. For example, I don't care if the input will be the classical Newick tree format, as suggested in this question. I am also ok with a non-automated process of creating such a tree, as I don't need to do it more than once probably.

Do you have any suggestions?

Best Answer

Here's a short example with the forest package. I made the lower part of the graph. Very basic, no colors, but that's up to you to change according to your taste.

Output

example

Code

\documentclass[margin=10pt]{standalone}
\usepackage{forest}

\usetikzlibrary{positioning, backgrounds}

\tikzset{
    timeline/.style={text centered, text width=2cm},
     no edge from this parent/.style={
        every child/.append style={
        edge from parent/.style={draw=none}}},
}

\forestset{
    every leaf node/.style={
        if n children=0{#1}{}
    },
    every tree node/.style={
        if n children=0{}{#1}
    },
    mytree/.style={
        for tree={
            edge path={
            \noexpand\path [draw, thick, \forestoption{edge}] (!u.parent anchor) |- (.child anchor)\forestoption{edge label};
            },
            every tree node={draw=none,inner sep=0, outer sep=0, minimum size=0},
            every leaf node/.style={align=left},
            grow'=0,
            parent anchor=east, 
            child anchor=west,
            anchor=west,
            l sep=2cm,
            s sep=3mm,
            draw=none,
    if n children=0{tier=word}{}
        }
    }
}

\begin{document}
\begin{forest} mytree
[,phantom, name=lvl0
    [,name=lvl1
        [,edge=dashed,name=lvl2
            [gray fox ] 
            [island fox,edge=dashed ]
        ]
        [
            [,name=lvl3
                [black bear ]
                [giant panda ] 
            ]
            [
                [northern elephant seal ]
                [walrus ] 
            ] 
        ] 
    ]
]
%
\coordinate (tml) at (0,-3.5);
\begin{scope}[on background layer]
\foreach \age [count=\x starting from 1] in {
    {10 million years ago},
    {7.4 million years ago},
    {4 million years ago}
    }{
    \node[timeline] (age\x) at (tml-|lvl\x) {\age};
    \draw[gray] (age\x) --++ (0,6);
}
\end{scope}
\end{forest}
\end{document}
Related Question