# Horizontal bargraph pgfplot

I'd like to make two graphs using TiKz pgfplots or otherwise using this table below. But get the error

! Package pgfplots Error: Sorry, the input coordinate Bloodstream Infection (B SI' has not been defined with 'symbolic y coords={Bloodstream Infection (BSI),S urgical site infections (SSI),Ventilator-associated pneumonia (VAP),Urinary tra ct infection (UTI),Others}... Maybe it has been misspelled?.

Have I not correctly defined the names in y coords?

**Type of infection Mean cost   Stdev   St dev Min  Stdev Max   %**
Bloodstream Infection (BSI) 36441   37078   2883    207256  14
Surgical site infections (SSI)  25546   39875   1783    134602  17
Ventilator-associated pneumonia (VAP)   9969    2920    7904    12034   14
Urinary tract infection (UTI)   1006    503 650 1361    33
Others  1000    1000    800 5000    22


 \documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
xbar, xmin=0,
xlabel={Percentage \%},
symbolic y coords={{Bloodstream Infection (BSI)},{Surgical site infections (SSI)},{Ventilator-associated pneumonia (VAP)},{Urinary tract infection (UTI)},{Others}},
ytick=data,
nodes near coords, nodes near coords align={horizontal},
ytick=data,
]
\addplot coordinates {(14,{Bloodstream Infection (BSI)}) (17,{Surgical site infections (SSI)}) (14,{Ventilator-associated pneumonia (VAP)}) (33,{Urinary tract infection (UTI)})(22, {Others})};
\end{axis}
\end{tikzpicture} %width=6cm,height=7.59cm

\end{document}

-
same problem. The closing parenthesis of (BSI fools pgfplots that coordinate is finished. Braces around them are needed –  percusse Mar 19 '13 at 18:29
Ahh thank you! I'm having a lot of trouble with braces today! What would the commands be to get the same colours do you know? –  HCAI Mar 19 '13 at 18:31
Updated code but continues to have problems –  HCAI Mar 19 '13 at 18:40
Remove the space in (22, {Others}). You only need braces if you want to protect spaces, commas etc. For single word you don't need them. Instead of this you can use numbers and then change the y tick labels. –  percusse Mar 19 '13 at 18:43
I understand, thank you. The first graph looks like it will take me all evening. –  HCAI Mar 19 '13 at 19:11

When symbolic coordinates are used, the pattern given by symbolic <x or y> coords should match exactly the pattern given in the coordinates. Hence the whitespace before {Others} should be removed.

Moreover, if there are characters such as parentheses or commas in the symbolic coordinate itself that would cause confusion during coordinate parsing of (<some text with ( or comma> , <some text with ( or comma>) they should be put withing brace pairs such that the parser will take them as a group of chars instead of finding a comma and start parsing the next coordinate.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
xbar, xmin=0,
xlabel={Percentage \%},
symbolic y coords={%
{Bloodstream Infection (BSI)},
{Surgical site infections (SSI)},
{Ventilator-associated pneumonia (VAP)},
{Urinary tract infection (UTI)},
Others},
ytick=data,
nodes near coords,
nodes near coords align={horizontal},
ytick=data,
]
`