# Ideas for drawing this plot?

I need idea for drawing the following graph. I, obviously, do not expect full code. I hope I can get an idea about the best way to plot this graph. Should I try to draw each rectangle separately? Is it better to draw it as a stacked bar chart?

-
Could you include an example of how your source data table is formatted? –  Jake Jan 31 '13 at 23:07
@Jake: Thank you for your comment. All I have is this picture. –  N Nik Jan 31 '13 at 23:09
Could you be more specific about what exactly you're trying to achieve? Are you after just the boxes, or do you also want the labels to be automatically placed like in the picture (that'll be hard)? Do you need to do this just once, or will you need to produce lots of similar plots with different data? What kind of data do you want to show? –  Jake Feb 1 '13 at 14:32
Take a look at TikZ (part of the pgf bundle) or asymptote.sourceforge.net. –  vonbrand Feb 1 '13 at 14:35

Here is a Tikz idea.

I defined the macro \drawboxes, aimed to typeset one of the columns in the plot. It receives two arguments:

• The first one is the width of the column
• The second is a comma separated list of values, which represent the heigth of each box (from bottom to top), in the same units than the axis. Internally it is scaled down so that 10 units is 5mm.

This macro draws the column of boxes, and also gives a name to each box, making easy to later add annotations on them, such as the numbers and lines pointing to the boxes. The names automatically asigned are (1), (2), and so on (also from bottom to top).

The following code draws the axis and the first column (I made up the values of the boxes, trying to get them similar to the figure you provided).

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}

\newcounter{node}
\def\drawboxes#1#2{ % width, list of heights of each box
\setcounter{node}{1}
\coordinate (aux);
\foreach \n/\h in {#2} {
\node[rectangle, minimum width=#1, minimum height=\h/2 mm, inner sep=0, draw,
above=0mm of aux, alias=aux] (\arabic{node}) {};
\stepcounter{node}
}
}

\begin{tikzpicture}[every node/.style={font=\scriptsize, inner sep=2pt}]
% Draw axis (the scale is 10 = 5mm
\draw[very thick] (0,0) -- (6,0) (0,0) -- (0,900/2 mm);
\foreach \i in {0,100,...,900}
\draw[thin] (0,\i/2 mm) -- +(-1mm, 0) node[left] {\i};

\begin{scope}[xshift=1.5cm]
% Draw the (empty) boxes
\drawboxes{1cm}{50,20,90,50,120,40,60,100,20,40};

% Add manually the external labels
\draw (1.east) -- +( 2mm, 2mm) node[right] {1};
\draw (2.west) -- +(-3mm, 3mm) node[left]  {2};
\draw (6.west) -- +(-3mm, 0mm) node[left]  {6};
\draw (9.east) -- +( 2mm, 2mm) node[right] {9};
\draw (10.west)-- +(-3mm, 3mm) node[left]  {10};

% Add in a loop the internal ones
\foreach \n in {3,4,5,7,8}
\node at (\n.center) {\n};

\node[below=2mm of 1] {Step 1};
\end{scope}
\end{tikzpicture}
\end{document}


Which produces:

I guess you can get the idea and write the remaining of the figure.

# Update.

I just noticed, after posting my answer, that the second and third columns do not start numbered in 1, so I added a third parameter to my \drawboxes to choose the name of the first box. The remaining are built in increasing order.

Here is the same example than above, but this time the boxes start in 11.

\documentclass{standalone} \usepackage{tikz} \usetikzlibrary{positioning} \begin{document}

\newcounter{node}
\def\drawboxes#1#2#3{ % width, name of the first node, list of heights of each box
\setcounter{node}{#2}
\coordinate (aux);
\foreach \n/\h in {#3} {
\node[rectangle, minimum width=#1, minimum height=\h/2 mm, inner sep=0, draw,
above=0mm of aux, alias=aux] (\arabic{node}) {};
\stepcounter{node}
}
}

\begin{tikzpicture}[every node/.style={font=\scriptsize, inner sep=2pt}]
% Draw axis (the scale is 10 = 5mm
\draw[very thick] (0,0) -- (6,0) (0,0) -- (0,900/2 mm);
\foreach \i in {0,100,...,900}
\draw[thin] (0,\i/2 mm) -- +(-1mm, 0) node[left] {\i};

\begin{scope}[xshift=1.5cm]
% Draw the (empty) boxes
\drawboxes{1cm}{11}{50,20,90,50,120,40,60,100,20,40};

% Add manually the external labels
\draw (11.east) -- +( 2mm, 2mm) node[right] {11};
\draw (12.west) -- +(-3mm, 3mm) node[left]  {12};
\draw (16.west) -- +(-3mm, 0mm) node[left]  {16};
\draw (19.east) -- +( 2mm, 2mm) node[right] {19};
\draw (20.west)-- +(-3mm, 3mm) node[left]  {20};

% Add in a loop the internal ones
\foreach \n in {13,14,15,17,18}
\node at (\n.center) {\n};

\node[below=2mm of 11] {Step 1};
\end{scope}
\end{tikzpicture}
\end{document}


-
woow, this is great! Thank you :) I didn't really expect to see a full code. Thanks, it was very nice of you :) –  N Nik Feb 1 '13 at 18:39

I would suggest using a capable vector drawing program like Inkscape (http://inkscape.org/), exporting the drawing as PDF and including using \includegraphics{drawing.pdf}.

This is by far the fastest and easiest way to get this graph into your document.

EDIT: I've seen the {tikz-pgf} {pgfplots} tags only after answering. Please consider rewriting your question more specific concerning the software / packages you are trying to use to accomplish your task.

-