1

I am trying to make a tornado plot that shows what the price will become when i change diffrent values, i want the x axis to be like the picture underneath with 77 as my base cost, but i can not figure out how i can get the bars on the left to go from 77 to the smaller cost, i have tried to use x dir=reverse, but then the axis reverse as well as the bars. Does anyone have some tips on how i can reverse the bars without reversing the axis?

enter image description here

\begin{figure}[!ht]
\pgfplotstableread[col sep=comma, header=true]{
unit,min,max
PE,77,86
Labour,77,82
ME,74,80
SI,75,79
ED,77,78
El,76,78
Land,76,78
}\loadedtable
\begin{center}
\resizebox{16cm}{!}{%
\begin{tikzpicture}
\begin{axis}[
    name=popaxis,
    scale only axis,
    xbar,
    xmin=77,
    xmax=87,
    width=10cm, height=8cm,
   y dir = reverse,
   nodes near coords = {\pgfmathprintnumber\pgfplotspointmeta},
   every node near coord/.append style={/pgf/number format/fixed, 
   font=\small, 
   color=black},
   xticklabel= {\pgfmathprintnumber\tick},
    y tick label style={text width=3cm,align=center},
    axis x line=left,
    axis y line=none,
    enlarge x limits = {value=0,upper},
    axis line style={-},
    clip=false
]
\addplot[gray,fill=lightgray!50] table[y expr =\coordindex, x expr={\thisrow{max}}] \loadedtable;
\pgfplotstablegetrowsof{\loadedtable}
\pgfmathsetmacro{\lastrow}{\pgfplotsretval-1}  

\end{axis}
\begin{axis}[ 
at={(popaxis.north west)},anchor=north east, xshift=0cm,
scale only axis,
    xbar,
    y dir=reverse,
   %x dir=reverse,
    xmin=67,
    xmax=77,
    width=10cm,
    height=8cm,
    nodes near coords = {\pgfmathprintnumber\pgfplotspointmeta},
    every node near coord/.append style={/pgf/number format/fixed, rotate = 0, anchor = east, font=\footnotesize,
    color=black},
    xticklabel= {\pgfmathprintnumber\tick},
    axis x line=left,
    axis y line*=right,
    ytick = data,
    yticklabels from table = {\loadedtable}{unit},
    ytick align=center,
    ytick pos=left,
    enlarge x limits = {value=0,upper},
    axis line style={-}
]
\addplot[gray,fill=lightgray!50] table[y expr =\coordindex, x expr={\thisrow{min}}] \loadedtable;
\end{axis}
\draw (0,0) -- (0,8);
\end{tikzpicture}
}
\end{center}
\end{figure}

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.