Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm making a bar chart with pgfplots and would like to put an asterisk above some bars to show statistical significance (p < 0.05). Any ideas?

Here's an example graph:

\begin{tikzpicture}
\begin{axis}[
    symbolic x coords={(a),(b),(c),(d),(e)},
    xtick=data]
    \addplot[ybar] coordinates {
        ((a),51365) % I'd like to put an asterisk above some of these
        ((b),74531)
        ((c),52862)
        ((d),78999)
        ((e),71825)
    };
\end{axis}
\end{tikzpicture}
share|improve this question
2  
Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. You can include a small data file or a table to demonstrate the plot you are working with. Use the search string [pgfplots] filecontents on this site for many examples. –  percusse Sep 30 '12 at 17:31
    
Thanks! Please see edit for a sample graph. –  stewartml Sep 30 '12 at 18:55
add comment

2 Answers

up vote 8 down vote accepted

I would use the nodes near coords functionality together with point meta=explicit symbolic for this:

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    symbolic x coords={(a),(b),(c),(d),(e)},
    xtick=data,
    ymin=0,
    point meta=explicit symbolic,
    nodes near coords    
    ]
    \addplot[ybar] table [meta index=2, header=false] {
       (a) 51365 *
       (b) 74531 \\
       (c) 52862 *
       (d) 78999 \\
       (e) 71825 \\
    };
\end{axis}
\end{tikzpicture}

\end{document}
share|improve this answer
    
This method is slightly nicer than Peter's, so I'm marking it as the answer, thanks. Why is there a comma between Y and Sig on the first line of the table? –  stewartml Oct 3 '12 at 13:54
    
@stewartml: Sorry, that comma wasn't supposed to be there. I've edited the answer slightly to do away with the column names. It sounds like you're not entirely happy with the answer, though? Could you elaborate on how you'd rather specify which results to highlight (or if there's anything else that's you're not happy with)? –  Jake Oct 3 '12 at 14:03
    
No, I think the answer is great thanks! Although Peter's works, I prefer yours, is all I meant. Nice and straightforward. –  stewartml Oct 3 '12 at 23:32
add comment

Not sure that this is a satisfactory answer but you could specify the xticklabels={(a),(b),(c),(d),(e)}, use numerical values for the x-values, and then place a node above the ones you want to highlight:

enter image description here

Code:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    xticklabels={(a),(b),(c),(d),(e)},
    xtick=data,
    ]
    \addplot[ybar] coordinates {
        (1,51365) % I'd like to put an asterisk above some of these
        (2,74531)
        (3,52862)
        (4,78999)
        (5,71825)
    };
\node [above, red, font=\Large] at (axis cs: 1,51365) {$\ast$};
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.