Take the following graph:
\documentclass[12pt,border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={group size=2 by 1,horizontal sep=5cm},
title style = {align=center},
xbar,
point meta=explicit symbolic,
nodes near coords,
nodes near coords align = {right},
y axis line style = { opacity = 0 },
axis x line = none,
tickwidth = 0pt,
y dir = reverse
]
\nextgroupplot[
ytick={1,2},
yticklabels={A,B},
title={First graph}
]
\addplot coordinates {
(20,1) [20]
(10,2) [10]
};
\nextgroupplot[
title={Second graph},
ytick={1,2},
yticklabels={A,Looooooooooong B}
]
\addplot coordinates {
(20,1) [20]
(30,2) [30]
};
\end{groupplot}
\end{tikzpicture}
\end{document}
This graph is confusing. To be able to compare the graphs the bar '20' in the first graph should be as long as the bar '20' in the second graph. Also, the bar '30' in the second graph should be 3 times as long as the bar '10' in the first graph.
How can I fix this problem?
I have tried a few fixes found in seemingly related threads, just as this one or this one, but they do not seem to work in my case. I think I simply do not understand why scaling works the way it does in pgfplots.
For example I thought that adding x=1cm in the options of \begin{groupplot} would fix my problem, my reasonning being that it would tell pgfplots that 1 unit has to be always 1cm whatever the graph. But it just makes the problem worse:

I then thought that maybe I should rescale the x-axis of the second plot. Since the largest number in the second plot, 30, is 50% larger than the largest number in the first plot, 20, maybe adding x post scale = 1.5 in the second graph would help? But no:

I believe the problem might come from the fact that I have a long label in the second graph, but adding the scale only axis option does not fix it.
I do not even need an automated solution, simply that 10 in whatever graph takes the same space.


xminthingy.) – Oct 24 '18 at 09:38xminandxmaxalso gets the desired result. What is the rationale for this behaviour? – darpich Oct 24 '18 at 09:39xmin=0they were no longer. That is to say that I also find this behavior a bit surprising. – Oct 24 '18 at 14:04