[Tex/LaTex] pgfplots grouped bar chart from file

pgfplotstikz-pgf

I am trying to create a grouped bar chart with pgfplots from a file that contains a data table. However in the resulting picture the bars are not grouped but on top of each other.

Every working example of grouped bar charts with pgfplots I found in the documentation, at stackoverflow or with google includes the coordinates in the tex file itself (those example work for me too).

The bars should be in pairs with one pair for each value of rounds. The first bar of each pair should be the corresponding value of RRS. The second bar of each pair should be the corresponding value of QRC.

My tex file

\documentclass[a4paper,10pt]{article}

\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotsset{compat=1.8}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[ybar]
    \pgfplotstableread{frequency_comparison_23.dat}\loadedtable;

    \addplot table[x=rounds, y=RRS] {\loadedtable};
    \addplot table[x=rounds, y=QRC] {\loadedtable};    
  \end{axis}
\end{tikzpicture}
\end{document}

And the table "frequency_comparison_23.dat"

vertices rounds RRS QRC
8388608 37 47 727
8388608 38 5731 15709
8388608 39 29072 35103
8388608 40 33027 26904
8388608 41 18914 13062
8388608 42 8141 5291
8388608 43 3177 1999
8388608 44 1179 766
8388608 45 435 273
8388608 46 175 104
8388608 47 59 43
8388608 48 26 11
8388608 49 9 5
8388608 50 6 3
8388608 51 1 0
8388608 52 1 0

Best Answer

You are using the default bar width option and they tend to overlap. If you adjust the bar width or the width of the plot it works.

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotsset{compat=1.8}

    \pgfplotstableread{
vertices rounds RRS QRC
8388608 37 47 727
8388608 38 5731 15709
8388608 39 29072 35103
8388608 40 33027 26904
8388608 41 18914 13062
8388608 42 8141 5291
8388608 43 3177 1999
8388608 44 1179 766
8388608 45 435 273
8388608 46 175 104
8388608 47 59 43
8388608 48 26 11
8388608 49 9 5
8388608 50 6 3
8388608 51 1 0
8388608 52 1 0
}\loadedtable;


\begin{document}
\begin{tikzpicture}
  \begin{axis}[ybar,bar width=2pt]
    \addplot table[x=rounds, y=RRS] {\loadedtable};
    \addplot table[x=rounds, y=QRC] {\loadedtable};    
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here