# Visualization backend for simple diagrams

Could someone recommend a solution for coding this kind of diagram into a TeX document?

Background: Looking for further ways to make everything in my papers replicable or at least communicable in an open format, I am trying to stop using OmniGraffle for simple diagrams like the one above, which are common in sociology, political science and probably other disciplines.

From a previous question, I understand that Graphviz and igraph might fit, but I do not understand exactly how more integrated to my TeX documents they would make my diagrams.

The best for me would probably be to understand how to replicate these graphs with TikZ, but I am not sure that this would work out easily, as I have been unable to locate a tutorial on the topic (trying to adapt commutative diagrams with TikZ to that kind of diagrams did not work out well).

-

## migrated from stats.stackexchange.comAug 27 '11 at 20:40

This question came from our site for people interested in statistics, machine learning, data analysis, data mining, and data visualization.

Agree: If you're interested in TikZ, then tex.SE is the way to go. I'll migrate your question for you. –  chl Aug 27 '11 at 20:40
From your question, it sounds as though this is some sort of "standard diagram" type in your field. Could you elaborate on how such data is specified? How much is one allowed to assume? I could easily draw this particular diagram in TikZ, but there are several ways to do it and the choice would depend on how the information is to be entered. Mentioning graphviz makes me think that you don't want to have to specify exactly where each piece of the diagram goes, is that correct? –  Loop Space Aug 27 '11 at 20:50

One way to draw such a diagram is to use node positioning. Here is a version that you can play around with.

\documentclass{minimal}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.markings}

\begin{document}

\begin{tikzpicture}[every node/.style={align=center,minimum width=4cm,minimum height=2cm,rectangle,outer sep=0pt},>=latex,
decoration={
markings,%  switch on markings
mark=at position 0.25  with {\draw (-4pt,-4pt) -- (4pt,4pt);\draw (4pt,-4pt) -- (-4pt,4pt);}}
]

\node (empty) {};
\node[below=of empty] (mech-1) {mechanism\\descriptor};
\node[below=of mech-1] (mech-2) {mechanism\\descriptor};

\node[right=of empty] (event) {\textbf{event}\\caption};

\node[draw,right=of mech-1] (process-1-1) {\textbf{process}\\caption};
\node[draw,right=of process-1-1] (process-1-2) {\textbf{process}\\caption};

\node[draw,right=3cm of mech-2] (process-2-1) {\textbf{intermediate process}};
\node[draw,right=of process-2-1] (process-2-2) {\textbf{intermediate process}};

\node[below=of process-2-1] (failure) {\textbf{failure}};
\node[below=of process-2-2] (success) {\textbf{success}};

\draw[->] (event) -- (process-1-1);
\draw[->] (process-1-1.south) -- (process-2-1.north);
\draw[->] (process-2-1.north) -- (process-1-2.south);
\draw[->] (process-1-2.south) -- (process-2-2.north);

\draw[postaction={decorate}] (process-2-1) -- (failure);
\draw[->] (process-2-2) -- (success);

\end{tikzpicture}

\end{document}


The result is

-
Thanks, that worked! I still find the syntax pretty obtuse, but I guess that's my reaction to the steep learning curve. –  Fr. Sep 23 '11 at 6:36

Chapter 3 of the pgf manual (including tikz) is a tutorial and the example it uses looks like it would apply to your graph above. There are also a bunch of examples here that you could work from, the examples in the 'chains' and 'node positioniong' sections look like they would apply to your example above.

-
I read through the manual, but replication of even simple examples failed in my XeTeX environment. –  Fr. Sep 23 '11 at 6:35

Here's another one combining Frédérik's use of the positioning library with Greg's suggestion of using the chains library with a couple of other libraries thrown in to the mix (in plain-format):

\font\ss=cmss9
\font\ssbf=cmssbx10 at 9pt
\font\ssit=cmssi9
\let\tenbf\ssbf
\let\tenit\ssit
\input tikz
\usetikzlibrary{
chains, % for the "start chain", "on chain", and "join" [manual section 28, p. 284]
arrows, % for the ">=triangle 45" [manual section 23, p. 256-]
positioning, % for the "left=<optional dimen> of ...",
% and "below left=<optional dimen(s)> of ..."
% [manual section 5.2, p. 62-]
decorations.markings, % for the "X" on a join [manual p. 327-]
shapes.multipart % for the "rectangle split" styles [manual p. 450-453]
}
\tikzpicture[
font=\ss,
node distance=1.5cm and -1cm, % the y distance and x distance of nodes
% ^the x distance is set to a negative value to reserve space
every node/.style={minimum width=3cm,align=center},
every on chain/.style=join,
every join/.style={->,thick,>=triangle 45},
mynode/.style={
on chain=going #1,
% ^you can give parameters to your styles, so that for example:
% node[mynode=below] expands to: node[on chain=going below]
inner xsep=1em,
rectangle split,rectangle split parts=2,
rectangle split ignore empty parts=true,
rectangle split draw splits=false,
every text node part/.style={font=\bf}},
myfail/.style={thick,-,postaction={decorate,decoration={markings,
% I have a feeling this could be accomplished more easily
mark=at position .25 with { \draw (-3pt,-3pt) -- (3pt,3pt)
(3pt,-3pt) -- (-3pt,3pt); }}}}
]

\def\npt{\nodepart{two}} % just a local definition to save typing

\draw[start chain]
node[mynode] {event\npt caption}
node[draw,mynode=below] (proc-1) {process\npt caption}
node[draw,mynode=below right] {intermediary process}
{[start branch,every join/.style=myfail]
node[mynode=below] {failure\npt caption}}
node[draw,mynode=above right] {process\npt caption}
node[draw,mynode=below right] {intermediary process}
node[mynode=below] {success\npt caption};

\draw[every node/.append style={align=left,font=\it}]
node[left=1cm of proc-1] (desc-1) {mechanism\\descriptor}
% ^without the "1cm", the node would've been -1cm left of proc-1
% because of the "node distance" definition for the whole tikzpicture
node[below=of desc-1] {mechanism\\descriptor};
\endtikzpicture
\bye


looks like:

-