3

This is my crude attempt to create a graph from copied example. I want to plot the diseases on the Yy axis and QoL scores on x axis. It has resulted in errors. Could anyone be kind enough to point out the problems?

\documentclass[tikz]{standalone}

\usepackage{pgfplots}

\begin{document}

\pgfplotstableread[row sep=\\,col sep=&]{
    Disease &    Score                                      \\
    Untreated HT&  108  \\
    Normal man &   105\\
    Normal woman & 104\\
    CHF (mild) & 95  \\
    Angina pectoris & 88 \\
    Untreated DU   & 83 \\
  Untreated GER  &  82 \\
  Psychiatric disease & 62 \\ 
      }\mydata

\begin{tikzpicture}
    \begin{axis}[
            ybar,
            bar width=.5cm,
            width=\textwidth,
            height=.5\textwidth,
            legend style={at={(0.5,1)},
                anchor=north,legend columns=-1},
            symbolic x coords={60, 65, 70, 75, 80,85, 90, 95, 100, 105, 110},
            xtick=data,
            nodes near coords,
            nodes near coords align={vertical},
            ymin=60 ,ymax=110
            ylabel={},
        ]
        \addplot table[x=score, y=Disease]{\mydata};

    \end{axis}
\end{tikzpicture}
\end{document}
1
  • There's a comma missing after your ymax=110.
    – user10274
    Feb 4 '14 at 16:47
3

Is this what you wanted?

screenshot

The main changes I made were

xbar,
...
symbolic y coords={Untreated HT, Normal man, 
            Normal woman, CHF (mild), Angina pectoris,Untreated DU, 
            Untreated GER, Psychiatric disease },
ytick=data,

to make it into an xbar graph.

% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass[tikz]{standalone}

\usepackage{pgfplots}

\begin{document}

\pgfplotstableread[row sep=\\,col sep=&]{%
    Disease &    Score                                      \\
    Untreated HT&  108  \\
    Normal man &   105\\
    Normal woman & 104\\
    CHF (mild) & 95  \\
    Angina pectoris & 88 \\
    Untreated DU   & 83 \\
    Untreated GER  &  82 \\
    Psychiatric disease & 62 \\ 
    }\mydata

\begin{tikzpicture}
    \begin{axis}[
            xbar,
            bar width=.5cm,
            width=\textwidth,
            height=.5\textwidth,
            legend style={at={(0.5,1)},
                anchor=north,legend columns=-1},
            %symbolic x coords={60, 65, 70, 75, 80,85, 90, 95, 100, 105, 110},
            symbolic y coords={Untreated HT, Normal man, 
                Normal woman, CHF (mild), Angina pectoris,Untreated DU, 
            Untreated GER, Psychiatric disease },
            ytick=data,
            nodes near coords,
            %nodes near coords align={vertical},
            %ymin=60 ,ymax=110,
            %ylabel={},
        ]
        \addplot table[x=Score, y=Disease]{\mydata};

    \end{axis}
\end{tikzpicture}
\end{document}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.