0

I can't find any guide about how to make a tornado plot in latex/overleaf. Does anybody know how to make one?

I'm working on an economical analysis and want to show how changes will affect the production cost.

Inspiration pictures:

Inspiration1Inspiration2

Edit: The question was marked to have a duplicate question, but I tried to use this one (How can I draw a pretty population pyramid graph with pgfplots?) as a base, but I'm not satisfied unfortunately, and I'm stuck.

Me trying my best

There is still a lot until I have it more equal to my two inspiration pictures, for instance:

  • The % values represent the % of the total. How do I remove them and rather show the change from the main value (?), as shown in the two example pictures?
  • How do I insert x- and y-axis?

I removed the header/title, it's not necessary as I will have a figure text underneath.

I'm sorry if I fail to explain my question, I'm as I mention very new to latex/overleaf :) I appreciate your feedback and answers!

(I also tried to use this: Creating a tornado plot with PGFPlots and force a break in one of the horizontal bars but I found that one to be even more difficult to understand. I want the y-axis not to be numbered, but with text, and don't know how to change that.)

\documentclass{standalone}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usepackage{pgfplotstable}
\usepackage{wasysym}
\begin{document}

\pgfplotstableread[col sep=comma]{
unit,min,max
Lipid content,1000,1300
Growth rate,800,1000
Main equipment cost basis,500,500
Operating factor,50,400
}\loadedtable

\newlength{\dy}\setlength{\dy}{\baselineskip}
\newlength{\dx}\setlength{\dx}{0.007em}
\newlength{\temp}

\pgfplotstablegetrowsof{\loadedtable}
\pgfmathparse{\pgfplotsretval-1}
\edef\rows{\pgfmathresult}
% compute total for percentages
\setlength{\temp}{0pt}
\foreach \y in {0,1,...,\rows}{%
  \pgfplotstablegetelem{\y}{min}\of\loadedtable
  \global\advance\temp by \pgfplotsretval pt
  \pgfplotstablegetelem{\y}{max}\of\loadedtable
  \global\advance\temp by \pgfplotsretval pt
}
\pgfmathparse{0.01\temp}
\edef\total{\pgfmathresult}

\noindent\begin{tikzpicture}

\foreach \y in {0,1,...,\rows}{%
  \pgfplotstablegetelem{\y}{unit}\of\loadedtable
  \node[left] at (-19em,-\y\dy) {\strut\pgfplotsretval};
  \pgfplotstablegetelem{\y}{min}\of\loadedtable
  \node[left] at (-15em,-\y\dy) {\strut\pgfplotsretval};
  \node[left,fill=Navy,text width=\pgfplotsretval\dx,text height=.8\dy,inner sep=0]
    at (0,-\y\dy+0.1\dy) {};
  \pgfmathparse{\pgfplotsretval/\total}
  \pgfmathprintnumberto[fixed,precision=2]{\pgfmathresult}{\per}
  \node[left] at (-\pgfplotsretval\dx,-\y\dy) {\small\strut\per\%};
  \pgfplotstablegetelem{\y}{max}\of\loadedtable
  \node[left] at (17em,-\y\dy) {\strut\pgfplotsretval};
  \node[right,fill=HotPink,text width=\pgfplotsretval\dx,text height=.8\dy,inner sep=0]
    at (0,-\y\dy+0.1\dy) {};
  \pgfmathparse{\pgfplotsretval/\total}
  \pgfmathprintnumberto[fixed,precision=2]{\pgfmathresult}{\per}
  \node[right] at (\pgfplotsretval\dx,-\y\dy) {\small\strut\per\%};
}

\end{tikzpicture}
\end{document}
  • Welcome to the TeX Stackexchange. – Sebastiano Mar 29 at 13:12
  • 2
    Can one do something like this? Most likely. Are many users here willing to write down a code from scratch and invent data to produce the output you want to have? Maybe not. So please show us what you've tried and what data you are using. – user121799 Mar 29 at 13:18
  • Hi @marmot, I see your point! I'm very new to latex, so I don't really have a starting point to show you, unfortunately. I've found tornado plots being used in a lot of other articles/reports, but no guides about how to make one in latex (I easily find guides/templates on how to make other diagrams). If no one has a template to show me (that they've perhaps already made), I'll just have to try create it in another program, excel for instance. – Signe Mar 29 at 13:35
  • Somewhat related: tex.stackexchange.com/questions/186759/… – John Kormylo Mar 29 at 14:22
  • I have now edited the question :) – Signe Apr 1 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.