[Tex/LaTex] How to draw state transition diagrams like this

diagramstikz-pgf

I'm doing a project on epidemiologies and I am reading a paper of which I really like the appearance of the transition state diagrams, but I can not get mine to look as good. Having an example would be a life saver. This is how they look on the article Example diagram

and this is how mine look

My diagram

Here's my code.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{babel,positioning,shapes}

\begin{document}
\begin{tikzpicture}
\tikzset{node distance=2.3cm, auto}
\node (0) {\footnotesize$\pi (S+V)$};
\node (1) [right of=0, xshift = -0.5cm, shape=rectangle,draw=black, fill=cyan] {$S$}; 
\node (2) [right of=1, shape=rectangle,draw=black, fill=white] {$E$};
\node (3) [right of=2, shape = rectangle, draw = black, fill = red] {$Z$};
\node (4) [below of=2, yshift=1cm] {\footnotesize$\alpha E$};
\node (5) [below of=3, yshift=1cm] {\footnotesize$\gamma (S+ V)Z$};
\node (6) [right of = 3, draw = black, fill = green] {$V$};
\node (7) [below of=6, shape = rectangle, yshift=1cm, text = white] {$V$};
\path (1.east) -- (1.north east) coordinate[pos=0.5] (a1);
\path (2.west) -- (2.north west) coordinate[pos=0.5] (b1);  
\path (6.south) -- (6.south east) coordinate[pos=0.5] (a6);
\path (6.south) -- (6.south west) coordinate[pos=0.5] (b6);
\path (7.north) -- (7.south east) coordinate[pos=0.5] (a7);
\path (7.south) -- (7.south west) coordinate[pos=0.5] (b7);
\draw[->] (0) to node {} (1);
\draw[->] (a1) to node {\footnotesize$\beta SZ$} (b1);
\path (1.east) -- (1.south east) coordinate[pos=0.5] (a2);
\path (2.west) -- (2.south west) coordinate[pos=0.5] (b2);
\draw[->] (a2) to[swap] node {\footnotesize$\delta S$} (b2);
\draw[->] (3) to node{} (5);
\draw[->] (2) to node{} (4);
\draw[->] (2) to node{\footnotesize $(1-\alpha)\lambda E$} (3);
\draw[->] (1) to[in=135,out=45]  node{\footnotesize$\zeta S$} (6);
\draw[->] (a6) to node{\footnotesize$\delta V$} (a7);
\draw[->] (b6) to[swap] node{\footnotesize$\beta VZ$} (b7);
\end{tikzpicture}

\end{document}

Thanks in advance!

Best Answer

I had a go at not only duplicating the style but also simplifying the code for increased ease of consistency/reusability.

I defined three styles: transition, state, and statecolor. transition is to be used for connecting arrows, and state for plain states such as E in this diagram. statecolor inherits all settings from the state style, but adds fill and draw colors based on an argument passed into the style key like so: statecolor=red.

>=stealth sets stealth arrow tips globally. node distance=2, on grid sets the positioning library up for nodes 2cm apart, center-to-center.

I converted each positioned node to use the preferred =of syntax for use with the positioning library. I also added the calc library to negate the need for the temporary coordinates on the node edges. If many states have multiple transitions, it may be convenient to add additional anchors to the shape, as described in Add more anchors to standard Tikz nodes.

The complete revised code:

\documentclass[tikz]{standalone}
\usetikzlibrary{calc,positioning}

\tikzset{
  transition/.style={font=\footnotesize, auto, inner sep=0.5ex},
  state/.style={font=\large, minimum size=1cm, draw, fill=white},
  statecolor/.style={state, draw=#1!70, fill=#1!30},
}

\begin{document}
\begin{tikzpicture}[>=stealth, node distance=2, on grid]
\node (S) [statecolor=blue] {$S$}; 
\node (E) [right=of S,state] {$E$};
\node (Z) [right=of E,statecolor=red] {$Z$};
\node (V) [right=of Z,statecolor=green] {$V$};
\draw[<-] (S) to +(-1,0) node[transition,left] {$\pi (S+V)$};
\draw[->] ($(S.east)!0.5!(S.north east)$) to node[transition] {$\beta SZ$} ($(E.west)!0.5!(E.north west)$);
\draw[->] ($(S.east)!0.5!(S.south east)$) to[swap,transition] node {$\delta S$} ($(E.west)!0.5!(E.south west)$);
\draw[->] (Z) to +(0,-1) node[transition,below] {$\gamma (S+ V)Z$};
\draw[->] (E) to +(0,-1) node[transition,below] {$(1-\alpha)\chi E$};
\draw[->] (E) to node[transition] { $\alpha\lambda E$} (Z);
\draw[->] (S) -- +(0,1) -| node[pos=0.25,transition] {$\zeta S$} (V);
\draw[->] ($(V.south)!0.5!(V.south east)$) to +(0,-1) node[transition,below] {$\beta VZ$};
\draw[->] ($(V.south)!0.5!(V.south west)$) to +(0,-0.5) node[transition,below] {$\delta V$};
\end{tikzpicture}
\end{document}

enter image description here