# How to make a pgfplots barplot not fuse with the y-axis?

I am making a barplot like below:

    \begin{tikzpicture}[baseline=(current bounding box.center)]
\begin{axis}[ symbolic x coords={$p$[A]=0.137, $p$[N]=0.488},
xtick=data,
axis x line*=bottom,
axis y line=left,
enlarge x limits={abs=bar},
yticklabels={,,},
ylabel=p-value,
x=3.5 cm,
ymin = 0,
ymax = 0.55,
bar width=0.7cm,
tick style={draw=none} ]
($p$[A]=0.137, 0.137)
($p$[N]=0.488, 0.488)
};

\coordinate (A) at (axis cs:Plain,0.5);
\coordinate (Alegend) at (axis cs:Plain,0.48);
\coordinate (B) at (axis cs:Plain,0.14);
\coordinate (Blegend) at (axis cs:Plain,0.160);
\coordinate (C) at (axis cs:Plain,0.13);
\coordinate (Clegend) at (axis cs:Plain,0.110);
\coordinate (O1) at (rel axis cs:0,0);
\coordinate (O2) at (rel axis cs:1,0);
\coordinate (O3) at (rel axis cs:0.5,0);

\draw [red,sharp plot,dashed] (A -| O1) -- (A -| O2);
\draw [red,sharp plot,dashed] (B -| O1) -- (B -| O2);
\draw [red,sharp plot,dashed] (C -| O1) -- (C -| O2);
\node[] at (Alegend -| O3) {\color{red}\footnotesize confidence=0.50};
\node[] at (Blegend -| O3) {\color{red}\footnotesize confidence=0.86};
\node[] at (Clegend -| O3) {\color{red}\footnotesize confidence=0.87};
\end{axis}
\end{tikzpicture}


And I would like some space between the y axis and the the first bar. Based on https://tex.stackexchange.com/a/64421/298 I though enlarge x limits={abs=bar}, would work but it does nothing... :/

EDIT:

I left Overleaf which seems to just swallow some errors and here is a bit of code that runs outside of Overleaf:

\documentclass[usenames,dvipsnames,12pt,oneside,article]{memoir}
\usepackage{hyperref}
\usepackage{microtype}
\usepackage{letltxmacro}
\usepackage[lining]{ebgaramond}
\usepackage[cmintegrals,cmbraces]{newtxmath}
\usepackage{ebgaramond-maths}
\usepackage{fontspec}
\usepackage{booktabs}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{enumitem}
\usepackage{rotating}
\usepackage{unicode-math}
\usepackage{booktabs}
\renewcommand{\thefootnote}{\color{red}\arabic{footnote}}

\usetikzlibrary{shapes.geometric, positioning, arrows.meta, decorations.pathreplacing}
\usetikzlibrary{calc}
\usetikzlibrary{shapes.misc}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[baseline=(current bounding box.center)]
\begin{axis}[ symbolic x coords={$p$[A]=0.137, $p$[N]=0.488},
xtick=data,
axis x line*=bottom,
axis y line=left,
%enlarge x limits={true,abs value=bar},
ytick = {0.15, 0.30, 0.45},
yticklabels={0.15,0.30,0.45},
ylabel=p-value,
x=3.5 cm,
ymin = 0,
ymax = 0.55,
bar width=0.7cm,
xtick style={draw=none} ]

($p$[A]=0.137, 0.137)
($p$[N]=0.488, 0.488)
};

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


• Your code is not compileable. – AndréC Nov 1 '18 at 14:32
• As @AndréC says, your code is not compilable, and it stays like this even if one adds a standard preamble since bar and Plain are not defined. And did you try to adjust xmin? – marmot Nov 1 '18 at 14:58
• Hm I did this with Overleaf and now realise that it seems to have eated some of the error messages. :/ @marmot I don't think that is possible when using symbolic x coords – jonalv Nov 1 '18 at 15:26
• Even with XeLaTeX, the edited code is still not compileable. Maybe you can share your document on overleaf? – AndréC Nov 1 '18 at 15:52
• Oh actually I ran it on lualatex... sry about that. That was perhaps a bit unclear... I got the feeling that overleaf was only private things. Gonna see if I can share things... – jonalv Nov 1 '18 at 15:54

I removed most of the irrelevant styles and just added enlarge x limits=0.2 to get

\documentclass[usenames,dvipsnames,12pt,oneside,article]{memoir}
% \usepackage{hyperref}
% \usepackage{microtype}
% \usepackage{letltxmacro}
% \usepackage[lining]{ebgaramond}
% \usepackage[cmintegrals,cmbraces]{newtxmath}
% \usepackage{ebgaramond-maths}
% \usepackage{fontspec}
% \usepackage{booktabs}
\usepackage{amssymb}
\usepackage{tikz}
% \usepackage{enumitem}
% \usepackage{rotating}
% \usepackage{unicode-math}
% \usepackage{booktabs}
\renewcommand{\thefootnote}{\color{red}\arabic{footnote}}

\usetikzlibrary{shapes.geometric, positioning, arrows.meta, decorations.pathreplacing}
\usetikzlibrary{calc}
\usetikzlibrary{shapes.misc}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[baseline=(current bounding box.center)]
\begin{axis}[ symbolic x coords={$p$[A]=0.137, $p$[N]=0.488},
xtick=data,
axis x line*=bottom,
axis y line=left,
enlarge x limits=0.2,
%enlarge x limits={true,abs value=bar},
ytick = {0.15, 0.30, 0.45},
yticklabels={0.15,0.30,0.45},
ylabel=p-value,
%xmin=-0.2,
x=3.5 cm,
ymin = 0,
ymax = 0.55,
bar width=0.7cm,
xtick style={draw=none} ]

($p$[A]=0.137, 0.137)
($p$[N]=0.488, 0.488)
};

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


• Yea that works... =) I got stuck on all that true, abs value= stuff... – jonalv Nov 1 '18 at 16:30

In addition to the solution given by @marmot, the pgfplots v1.16 manual specifies that this problem comes from the key symbolic x coords={}.

I quote the manual 1.16 page 385:

Symbolic coords are useful since they reduce the burden to map strings to indices and vice versa.

However, they have a caveat: what if you want to set xmin to something to the left of the first symbolic x coord?

This is impossible since any input coordinate is expected to be contained in symbolic x coord. To allow such modifications nevertheless, pgfplots checks for the magic prefix [normalized]:

Whenever pgfplots finds a symbolic coordinate which starts with the precise string [normalized], it will interpret everything after the prefix to be a normalized number and no symbol. In our example, xmin will be set to -1:7, i.e. something to the left of a (which would be 0 according to the definition above).

So I added this code: xmin={{[normalized]-0.2},and everything works!

\documentclass[usenames,dvipsnames,12pt,oneside,article]{memoir}
\usepackage{amssymb}
\usepackage{tikz}
\renewcommand{\thefootnote}{\color{red}\arabic{footnote}}

\usetikzlibrary{shapes.geometric, positioning, arrows.meta, decorations.pathreplacing}
\usetikzlibrary{calc}
\usetikzlibrary{shapes.misc}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[baseline=(current bounding box.center)]
\begin{axis}[ symbolic x coords={$p$[A]=0.137, $p$[N]=0.488},
xtick=data,
axis x line*=bottom,
axis y line=left,
ytick = {0.15, 0.30, 0.45},
yticklabels={0.15,0.30,0.45},
ylabel=p-value,
xmin={[normalized]-0.2},
x=3.5 cm,
ymin = 0,
ymax = 0.55,
bar width=0.7cm,
xtick style={draw=none} ]

($p$[A]=0.137, 0.137)
($p$[N]=0.488, 0.488)