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 did an ANOVA with 4 tests. Result graph is shown here, original code comes from: TikZ: Replacing the values (labels) on x-axis with names

\documentclass[12pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}

\begin{document}
\begin{tikzpicture}
    \begin{axis}
        [
        ,width=7cm
        ,xlabel=Test
        ,ylabel=Mean
        ,xtick=data,
       %,xtick={0,1,...,3}
        ,xticklabels={Test A,Test B,Test C,Test D}
        ]
        \addplot+[sharp plot] coordinates
        {(0,18.26) (1,21.47) (2,24.58) (3,24.95)};
    \end{axis}
\end{tikzpicture}
\end{document}

Problem: I want to add additional lines which indicate the results of pairwise comparisions as displayed in the example below:

Repeated measurement with pairwise comparisions

  1. I could manually arrange further lines - is there a more elegant way?

  2. How do I add the *** and ** near the lines?

  3. How do I get a dotted line with arrows as endings?

share|improve this question
1  
as displayed in the example below... is something missing from your question? –  cmhughes Jun 29 at 19:28
    
The graph was missing, now it's included :) –  Jens Jun 29 at 19:36

1 Answer 1

up vote 3 down vote accepted

For this specific case a quick and easy way is to add something like

\draw [dotted,->] ([xshift=0.3cm]axis cs:0,18.26) -- ([yshift=-0.3cm]axis cs:2,24.58) node[near end,right,font=\tiny]{***};
\draw [dotted,->,shorten >=0.3cm] (axis cs:0.2,18.26) -- (axis cs:3,24.95) node[near end,right,font=\tiny]{**};   

just before \end{axis}.

  • dotted,-> specifies that the line should be dotted and have the default arrow head.

  • A coordinate such as axis cs:0,18.26 means that the coordinate system of the axis should be used. When [xshift=0.3cm] is placed at the start of the coordinate as in ([xshift=0.3cm]axis cs:0,18.26) it moves the coordinate 0.3cm to the right. Similarly for yshift.

  • node[near end,right,font=\tiny]{**} places a node to the right of the line, near the end, and sets it with \tiny font size.

  • shorten >=0.3cm cuts off 0.3cm at the end of the line.

Note that all the coordinates used are the same as those of the plot itself, so the lines are drawn relative to them.

enter image description here

\documentclass[12pt,border=4mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}

\begin{document}
\begin{tikzpicture}
    \begin{axis}
        [
        ,width=7cm
        ,xlabel=Test
        ,ylabel=Mean
        ,xtick=data,
       %,xtick={0,1,...,3}
        ,xticklabels={Test A,Test B,Test C,Test D}
        ]
        \addplot+[sharp plot] coordinates
        {(0,18.26) (1,21.47) (2,24.58) (3,24.95)};

        \draw [dotted,->] ([xshift=0.3cm]axis cs:0,18.26) -- ([yshift=-0.3cm]axis cs:2,24.58) node[near end,right,font=\tiny]{***};
        \draw [dotted,->,shorten >=0.3cm] (axis cs:0.2,18.26) -- (axis cs:3,24.95) node[near end,right,font=\tiny]{**};        
    \end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
Decent and good solution!! –  Jens Jun 29 at 20:07
    
Luxus problems: I wonder if it is possible set a better looking arrow like shown in the answer to this question: tex.stackexchange.com/questions/69195/… –  Jens Jun 29 at 22:31
1  
@Jens use -stealth instead of ->. –  Torbjørn T. Jun 29 at 22:37

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.