1

I try to add significance markers to my graphs that I made with pgfplots. In an answer to another question here I found the possibility to add \draw and \node into the code to draw a line with a asterisk above. The code in the working example produces a figure that looks like the one in the first picture, but I would rather like to have something like the second picture (asterisk in the middle and small vertical lines that mark the end of the horicontal line).

Could somebody help me? Thank you!

\documentclass{apa6}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
ybar,
enlargelimits=0.15,
height=0.7\textwidth,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ylabel={Pupillenweite},
symbolic x coords={Baseline,Stimulus},
xtick=data,
]
%neutral
\addplot[blue,fill=blue!30!white,error bars/.cd,y dir=both,y explicit,]
coordinates{(Baseline,0.0476) +-(0.02117,0.02117) (Stimulus,-0.1809) +-(0.01841,0.01841)};
%negativ
\addplot[red,fill=red!30!white,error bars/.cd,y dir=both,y explicit,]
coordinates{(Baseline,0.0342) +-(0.02073,0.02073) (Stimulus,0.1013) +-(0.01904,0.01904)};
                \draw (axis cs:Baseline,0.1) ++ (-10pt,0pt) -- ++(280pt,0pt);
                \node[anchor=south] at (axis cs:Baseline,0.1) {*};

\legend{neutral,emotional}
\end{axis}
\end{tikzpicture}

\end{document}

Figure produced by my code Figure that I would like to have

Sebastiano
  • 54,118
Anne B.
  • 165

1 Answers1

1

Quick and dirty, I would add

\usetikzlibrary{arrows.meta}

to the preamble, and then

   \draw [arrows={Bar[left]-Bar[right]},  shorten <= -10pt, shorten >=5pt] 
        (axis cs:Baseline,0.1) -- node[midway, above]{*} (axis cs:Stimulus,0.1);
    \draw [arrows={Bar[left]-Bar[right]}, ] 
        (axis cs:Stimulus,0.14) ++(-10pt, 0) -- node[midway, above]{*} ++(30pt,0);

to obtain:

partial shot of the result

Notice that the first asterisk is not exactly centered, due to the shorten keys; it's not difficult to change that doing something similar to the second line (where it's centered).

You can find a lot about arrows.meta in section 16 of the manual.

Rmano
  • 40,848
  • 3
  • 64
  • 125
  • Thanks, that works perfectly in my working example! But when I put it in my original file I get an error message: "! Package pgfplots Error: Sorry, the input coordinate `0' has not been defined with 'symbolic x coords={Baseline,Stimulus}... Maybe it has been misspelled? Or did you mean something like [normalized]0?." Do you (or anybody else) have any idea why this happens? – Anne B. Sep 26 '17 at 06:50
  • ...hmmm... try adding \pgfplotset{compat=1.13} in the preamble. And maybe you'll need some [ https://tex.stackexchange.com/questions/332553/problems-with-relative-axis-cs-coordinates-in-pgfplots ](axis direction cs:) somewhere. No time now, try to post another question! – Rmano Sep 26 '17 at 07:17
  • Thanks, I posted it as a new question (https://tex.stackexchange.com/questions/393276/pgfplots-problems-with-pgfplotssetcompat-1-13-and-drawing-arrows)! – Anne B. Sep 26 '17 at 07:33