[Tex/LaTex] Set axis x line to other origin than 0

pgfplots

I am trying to make a ybar axis that averages from the middle, but I cannot find a way to change the origin of the x axis.

This is what I want:

The x line should start at 3

This is what I have:

The x line is starting at the bottom

As you can see, I am trying to make an average. Can I do it like this or do I have to transform my data?

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
    \pgfplotstableread{data/singlecontrol.dat}\datatable

    \begin{axis}[ybar,
    xticklabels from table={\datatable}{variable},
    xtick=data,
    axis x line=middle,
    ymin=1,
    ymax=5
    ]

    \addplot table[x=X,y=averagejs] {\datatable};
    \addlegendentry{Joystick}
    \addplot table[x=X,y=averagem] {\datatable};
    \addlegendentry{Mouse}
    \end{axis}
\end{tikzpicture}
\end{document}

Best Answer

ybar plots always start from y=0. So what you'll have to do is change the tick labels on the y axis, so that 0 "looks like" 3, and subtract 3 from the data values, which you can do using a y filter/.code.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
    \pgfplotstableread{
    X averagejs averagem variable
    1 3.5 3.7 A
    2 4 4.4 B
    3 3.6 3.9 C   
    }\datatable

    \begin{axis}[ybar,
    xticklabels from table={\datatable}{variable},
    xtick=data,
    axis x line*=middle,
    enlarge x limits,
    y filter/.code={\pgfmathparse{#1-3}},
    ymin=-2, ymax=2,
    yticklabel={\pgfmathparse{\tick+3}\pgfmathprintnumber{\pgfmathresult}}
    ]

    \addplot table[x=X,y=averagejs] {\datatable};
    \addlegendentry{Joystick}
    \addplot table[x=X,y=averagem] {\datatable};
    \addlegendentry{Mouse}
    \end{axis}
\end{tikzpicture}
\end{document}