# Putting a time-scale in a tikz diagram and aligning nodes with the time axis?

I'm looking to reproduce a diagram using the tikz package from a paper in JASA: Moodie et al 2009 104(485):155-65. This is the figure:

The nodes and arrows don't seem too difficult to generate. But I'm stumped on how to put a timescale axis, and space the nodes so that they align with it. So, to make this question relevant to a more general audience, how does one put an x-axis on the bottom of a tikz diagram, and align the nodes with elements on the axis?

Here's a starting example for time-points 0 and 1:

\begin{tikzpicture}[line width=0.05cm]
\node [circle,draw] (h1) at (0,2) {$h$};
\node [circle,draw] (h2) at (2,2) {$h$};

\node [circle,draw] (b1) at (1.5,4) {$b$};

\begin{scope}[line width=.1cm,shorten >= 5pt, shorten <= 5pt]
\draw[->] (h1) -- (h2);
\draw[->] (h1) -- (b1);
\draw[->] (b1) -- (h2);

\end{scope}
\draw[help lines] (0,0) grid (5,5) ;
\end{tikzpicture}


I'm looking for what I can add to this code to get the time-axis (lines, tick marks, numbers, and title).

-
you can put the nodes on a grid. Or you could fake the timescale as nodes below the lower nodes. –  papabravo Feb 14 '14 at 14:39

Tikz knows quite a lot about repetitive jobs. Here is a shorter version of Nicos answer:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%%plot the wt nodes and timeline ticks
\foreach \x in {0,1,2,3,6,9,12} {
\draw (\x ,0) node[anchor=north] {\x} -- (\x,0.1);
\node[draw,circle] (wt\x) at (\x,1) {wt};
};
%%plot the bt nodes and most edges
%%alternative for older tikz versions:
%\def\lastx{0}
%\foreach[remember =\x as \lastx] \x in {1,2,3,6,9,12} {
%%works for me with current version (3.0.0)
\foreach[remember =\x as \lastx (initially 0)] \x in {1,2,3,6,9,12} {
\node[draw,circle] (bf\lastx) at (0.5+\lastx,2) {bf};
\path[->] (wt\lastx) edge (wt\x);
\path[->] (wt\lastx) edge (bf\lastx);
\path[->] (bf\lastx) edge (wt\x);
}
%%plot the missing edges
\foreach[remember =\x as \lastx (initially 0)] \x in {1,2,3,6,9} {
\path[->] (bf\lastx) edge (bf\x);
}
\draw[->] (-.5,0) -- (12.5,0);
\end{tikzpicture}
\end{document}


Edit: Added alternative version according to this.

The Result :

-
Does it compile? –  ajeh Feb 14 '14 at 15:50
It does for me. Maybe the remember key is new in tikz 3.0? I just learnt about it... –  papabravo Feb 14 '14 at 15:56
@papabravo, your approach is enticing, but there seems to be a mistake (typo?) in your code that I can't find. There is only one node for bf, and the arrows aren't quite working out. –  user1849779 Feb 14 '14 at 16:00
I should definitely learn this kind of stuff. –  Nico Feb 14 '14 at 16:10
Added a version that should work with the 2.1 version. Haven't tested it because I don't want to mess with my installation (I'm happy it's running...) –  papabravo Feb 14 '14 at 16:15

For something as simple as this I would KISS.

If you are a newbie like me, the simpler the better.

\documentclass[10pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}

\begin{document}
\begin{tikzpicture}
[node distance=4mm and 1.75mm, bubbles/.style={draw,circle, minimum size=2em}]
% Bottom
\node[bubbles] (wt0) at (0, 0) {wt};
\node[bubbles] (wt1) at (1, 0) {wt};
\node[bubbles] (wt2) at (2, 0) {wt};
\node[bubbles] (wt3) at (3, 0) {wt};
\node[bubbles] (wt6) at (6, 0) {wt};
\node[bubbles] (wt9) at (9, 0) {wt};
\node[bubbles] (wt12) at (12, 0) {wt};

% Top
\node[bubbles] (bf0) [above right=of wt0] {bf};
\node[bubbles] (bf1) [above right=of wt1] {bf};
\node[bubbles] (bf2) [above right=of wt2] {bf};
\node[bubbles] (bf3) [above right=of wt3] {bf};
\node[bubbles] (bf6) [above right=of wt6] {bf};
\node[bubbles] (bf9) [above right=of wt9] {bf};

% Arrows
\draw [-latex,thick](wt0) -- (bf0);
\draw [-latex,thick](wt0) -- (wt1);
% And so on

% Timeline
\node at (0, -1) {0};
\node at (1, -1) {1};
\node at (2, -1) {2};
\node at (3, -1) {3};
\node at (6, -1) {6};
\node at (9, -1) {9};
\node at (12, -1) {12};
\end{tikzpicture}
\end{document}


Explanation:

• Put the bottom nodes at the position you want. You can use months number like I did.
• Put the top nodes relative to the bottom nodes (that's what it looks like in the picture you put)
• Arrows are pretty straightforward.
• Timeline: The nodes are in the same place as the bottom nodes.
-