I'm trying to draw a bar diagram but it seems that the bars are reversed.
Let's take "Canada" for example, I would like to have 48 as first value, 24 and then 59, not the other way around. I can't figure out how to reverse the bars.
Resulting wrong image and code below.
\documentclass[margin=5mm]{standalone}
\usepackage{pgfplots, pgfplotstable}
\pgfplotsset{compat = newest}
\begin{document}
\pgfplotstableread[header = true, col sep = comma]{
State, Science, Engineering, Bachelor
Canada, 48, 24, 59
France, 38, 31, 55
Germany, 44, 22, 54
Italy, 55, 39, 62
Spain, 44, 32, 57
Sweden, 44, 30, 62
UK, 38, 23, 56
US, 43, 22, 57
OECD, 42, 27, 58
}{\datatable}
\begin{tikzpicture}[scale=1]
\begin{axis}[
,width = 6in, height = 12cm
,xbar
,xmajorgrids
,tickwidth = 0pt
,x axis line style = { opacity = 0 }
,xlabel = {\textbf{Percent (\%) Female Graduates}}
,ylabel = {\textbf{States}}
,xbar = 2pt% space of 2pt between adjacent bars
,bar width = 7pt
,xmin = 0, xmax = 70
,ytick = data% crucial line for the yticklabels directive
,yticklabels from table = {\datatable}{State}
,nodes near coords
,every node near coord/.append style={font=\ttfamily\footnotesize}
,y tick label style = {
,rotate = 0
,anchor = east
}
,legend style = {
,draw = none
,anchor = north
,at = {(0.5,-0.125)}
,legend columns = 3
,legend style={
/tikz/every even column/.append style={column sep=.5cm},
/tikz/every odd column/.append style={column sep=.1cm}
}
,align = left
}
,cycle list name = exotic
,every axis plot/.append style = {fill, draw = none, no markers}%
]
\foreach \i in {Science, Engineering, Bachelor} {
\addplot+ table [
y expr=-\coordindex,% Use negative coordinate index as y coordinate
x=\i,
]{\datatable};
}
\legend{Sciences, Engineering, All bachelor programs}
\end{axis}
\end{tikzpicture}
\end{document}