5

I've got a bar graph with two bars for each of the two groups. Below is my MWE. I've been struggling to work out how to draw an upward arrow between the blue bar and the red bar for Gen 1 group, and a downward arrow between the blue bar and the red bar for Gen 2.

If someone could please help that'd be extremely helpful.

\begin{figure}
    \centering
    \begin{tikzpicture}
\begin{axis}[
    ybar, bar width=23pt,
    ymajorgrids=true,
    grid style=dashed,
    enlarge x limits=0.4,
    % legend style={at={(1.2, 0.5), \footnotesize},
    %   anchor=west,legend columns=1.8},
    legend style={anchor=north east,legend columns=1.8,font=\footnotesize},    
    ylabel={\% of the total ML-identifable mixed clauses},
    symbolic x coords={Gen1, Gen2},
    xtick=data,
    ymin=0,
    ymax=100,
    ytick={10,30,50,70,90},
    nodes near coords,
    point meta=explicit symbolic
    ]
\addplot coordinates {(Gen1,22)[{141}] (Gen2,53)[{273}]}; 
\addplot coordinates {(Gen1,78)[{510}] (Gen2,47)[{242}]};
\legend{E ML, V ML}
\end{axis}
\end{tikzpicture}
    \caption{Opposite distribution}
    \label{fg:MLdistribution}
\end{figure}

1 Answers1

6

You can name the nodes near coords and use them.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\pgfplotsset{% https://tex.stackexchange.com/a/75811/194703
    name nodes near coords/.style={
        every node near coord/.append style={
            name=#1-\coordindex,
            alias=#1-last,
        },
    },
    name nodes near coords/.default=coordnode
}
\begin{document}

\begin{figure}
    \centering
    \begin{tikzpicture}
\begin{axis}[
    ybar, bar width=23pt,
    ymajorgrids=true,
    grid style=dashed,
    enlarge x limits=0.4,
    % legend style={at={(1.2, 0.5), \footnotesize},
    %   anchor=west,legend columns=1.8},
    legend style={anchor=north east,legend columns=1.8,font=\footnotesize},    
    ylabel={\% of the total ML-identifable mixed clauses},
    symbolic x coords={Gen1, Gen2},
    xtick=data,
    ymin=0,
    ymax=100,
    ytick={10,30,50,70,90},
    nodes near coords,
    point meta=explicit symbolic
    ]
\addplot+[name nodes near coords=bn] coordinates {(Gen1,22)[{141}] (Gen2,53)[{273}]}; 
\addplot+[name nodes near coords=rn] coordinates {(Gen1,78)[{510}] (Gen2,47)[{242}]};
\legend{E ML, V ML}
\end{axis}
\draw[thick,-latex] (bn-0.north) -- (rn-0.south);
\draw[thick,-latex] (bn-1.east) -- (rn-1.north);
\end{tikzpicture}
\caption{Opposite distribution}
\label{fg:MLdistribution}
\end{figure}
\end{document}

enter image description here

  • Thank you so much for your help. Yes the arrow should go like this, but i'd like them to go between the numbers, i.e. starting from slightly above 141 to just below 510, and similarly from just below 273 to just above 242. If you can show me how to achieve this, that'd be extremely helpful. Thank you! – teadrinker64 Nov 06 '19 at 00:53
  • @teadrinker64 Better now? (You can use any anchor of the nodes that got auto-named with Jake's linked answer.) –  Nov 06 '19 at 01:00
  • perfect, thank you. – teadrinker64 Nov 06 '19 at 01:17