# Bar chart vertical alignment and scaling

I'm having problems with the vertical alignment of my bar chart. I started using a single xbar chart for my data, but it looked terrible, since one item is very large and the other very small. So, i had the idea of making multiple charts for each item, but the don't really align.This is the first version, where the scaling is catastrophic. I want to be able to compare the different plots.

If i try to make multiple xbar charts, they are not aligned.

\documentclass{report}
\usepackage{pgfplots}
\usepackage{tikz}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[tickwidth = 0pt,xbar, xmin=0, width=12cm, height=3.5cm, enlarge y limits=0.5, symbolic y coords={no,yes}, ytick=data, nodes near coords,y axis line style = { opacity = 0 },
axis x line       = none ]
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[  tickwidth= 0pt,xbar, xmin=0, width=12cm, height=3.5cm, enlarge y limits=0.5, symbolic y coords={noooooo,yeeeeees}, ytick=data, nodes near coords,y axis line style = { opacity = 0 },
axis x line       = none ]
\end{axis}
\end{tikzpicture}
\end{figure}

\begin{figure}
\begin{tikzpicture}
\begin{axis}[  tickwidth= 0pt,xbar, xmin=0, enlarge y limits=0.5, symbolic y coords={noooooo,yeeeeees, yes, no}, ytick=data, nodes near coords,y axis line style = { opacity = 0 },
axis x line       = none ]
\addplot coordinates {(3,noooooo) (7,yeeeeees) (1000000,yes) (2000000,no)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

I guess the easiest way to align the plots vertically is to simply make use of the groupplots library.

(Please note that there currently seems to be a bug when symbolic coords are used in a groupplot. That is why I needed to use a different approach to provide the data. And because I anyway was "forced" to restate the data I also switched them from coordinates to table which is much more flexible (as well).)

For the details please have a look at the comments in the code.

% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
% load the groupplots library
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={
% define groupplot size (2 vertical plots) ...
group size=1 by 2,
% ... and the distance between the plots
vertical sep=5mm,
},
% (here are your options which are in common for all plots)
width=12cm,
height=3.5cm,
tickwidth=0pt,
xbar,
xmin=0,
enlarge y limits={abs=0.5},     % <-- (adapted)
ytick=data,
nodes near coords,
y axis line style={opacity=0},
axis x line=none,
legend style={
% position the legend below the plot
at={(0.0,-0.1)},
anchor=north west,
% (add the rest of style you want to use here)
},
% use the coordinate index for the y value
% (which is needed after restating the data coordinates to a table)
table/y expr={\coordindex},
]
% start the first plot
\nextgroupplot[
% names to be stated as yticklabels
% (which were before the symbolic y coords)
yticklabels={no,yes},
]
% restated data from coordinates to table which is much simpler
% (one could also combine all data in a single data file and call
%  different columns from that here)
1000000
2000000
};
4000000
1000000
};
\nextgroupplot[yticklabels={noooooo,yeeeeees}]
3
7
};
% add the legend entries to the last \nextgroupplot